0

I had read earlier that cross domain requests are not possible through AJAX (since XHR is bound to same origin policy)... Hence we use JSONP, which uses dynamic script injection (since script tag is not bound by same origin policy).

However, I was going through the jQuery AJAX documentation and saw one setting saying "crossDomain".

So, is Cross domain requests now supported through jQuery/AJAX? Is it the same as what we get through JSONP?

4

1 回答 1

0

我做了一个使用跨域请求的项目。你有几个例子。

它在这里,在 Github 上。

在您的客户端代码 (javascript) 中使用此函数:

function getHTML(url, callback){
    url = url.trim();

    $.ajax({
        url: url,
        type: 'GET',
        success: function(res) {
            var headline = res.responseText;

            if(headline === ""){
                callback("There was a problem with the page. Be sure that your url is correct.");
                return;
            }

            callback(null, headline);
        }
    });
}
于 2013-03-17T07:10:13.373 回答