Post JSON data cross site using jquery [duplicate]
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".
精彩评论