开发者

Post JSON data cross site using jquery [duplicate]

This question already has answers here: Closed 11 years ago.

Possible 开发者_StackOverflow社区Duplicate:

Cross-site AJAX using jQuery

I am trying to post json to a different site to render an image:

jdata holds my JSON data and all this is done under a click event.

$.ajax ({
    type: 'POST',
    dataType: 'jsonp',
    jsonp: jdata,
    url: 'the site url',
    success: function() {
        alert('hi');
    }

});

EDIT: sorry for not posting the problem... I can't seem to post the data to a different site. Is my syntax correct? I looked at the other cross site post here on stack overflow, but I keep posting to "http://siteiAmOn.com/siteIWanttoGoto"


Based on this:

I keep posting to "http://siteiAmOn.com/siteIWanttoGoto"

It sounds like you didn't add "http://" to 'the site url'. Add that and see if it helps.

Also, is it intentional here that jdata is a variable: jsonp: jdata?


You cannot post the json to another site due to Cross site restrictions. You may have to use scripttag proxy (allows only GET method). Another way is to write a simple server side proxy that will proxy your client side request to the other site. Look for "Cross Domain Javascript issues".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜