开发者

How to post cross domain data and get a response using php and jquery

开发者 https://www.devze.com 2023-04-02 23:39 出处:网络
Im trying to create a bookmarklet that allows users to post a lot of cross domain data to a php script and get a response from the php script using开发者_运维问答 jquery. What is the best way to do th

Im trying to create a bookmarklet that allows users to post a lot of cross domain data to a php script and get a response from the php script using开发者_运维问答 jquery. What is the best way to do this


Your best shot will be to use JSONP:

JSONP or "JSON with padding" is a complement to the base JSON data format, a pattern of usage allowing a page to request data from a server in a different domain. JSONP is a solution to this problem, forming an alternative to a more recent method called Cross-Origin Resource Sharing.

jQuery implements JSONP. Try and test this code:

$.ajax( {
  url: 'http://…',
  dataType: 'jsonp',
  complete: function(xmlHttpReq, textStatus) {…}
});


I recommend checking out JavaScript: Use a Web Proxy for Cross-Domain XMLHttpRequest Calls


Tricky because Cross Site Scripting gets blocked by most browsers. My solution was to write the data to a file and then access that file from php. Pass the data through a file in other words.

0

精彩评论

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

关注公众号