Я создаю небольшое клиентское приложение, которое развертывается на веб-сайте, созданном с помощью CMS WYSIWYG. (К сожалению, у меня нет доступа к серверу).
Я сохраняю состояние приложения в URL-адресе с помощью хэш-банга и хотел бы сократить его, используя что-то вроде API создания TinyURL. По сути, я хотел бы запросить стороннюю службу с моим длинным URL-адресом в качестве запроса и получить ответ с сокращенным.
Моя проблема в том, что я не знаю, как это сделать, не получая сообщение об ошибке CORS: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://www.site-im-working-on.com' is therefore not allowed access.
Вот пример того, что я пытался сделать (используя jQuery):
var tinyAPI = 'http://tinyurl.com/api-create.php?url='; function getTinyURL () { var longURL = window.location.href; var request = tinyAPI + longURL; return $.get( request, function (response) { return response; }); } // get tiny URL when on user action $('.share-button').on('click', function () { var tinyURL = tinyURL(); // insert string into DOM element // copy string to user's clipboard // etc... });
Есть ли способ обойти CORS, используя только клиентскую часть? код?
(Я также готов использовать другой сокращатель URL-адресов с бесплатным API.)