Loading cross-domain endpoint with AJAX

前端 未结 9 1710
醉酒成梦
醉酒成梦 2020-11-21 05:20

I\'m trying to load a cross-domain HTML page using AJAX but unless the dataType is \"jsonp\" I can\'t get a response. However using jsonp the browser is expecting a script m

9条回答
  •  旧时难觅i
    2020-11-21 06:03

    You can use Ajax-cross-origin a jQuery plugin. With this plugin you use jQuery.ajax() cross domain. It uses Google services to achieve this:

    The AJAX Cross Origin plugin use Google Apps Script as a proxy jSON getter where jSONP is not implemented. When you set the crossOrigin option to true, the plugin replace the original url with the Google Apps Script address and send it as encoded url parameter. The Google Apps Script use Google Servers resources to get the remote data, and return it back to the client as JSONP.

    It is very simple to use:

        $.ajax({
            crossOrigin: true,
            url: url,
            success: function(data) {
                console.log(data);
            }
        });
    

    You can read more here: http://www.ajax-cross-origin.com/

提交回复
热议问题