开发者

Javascript widget works fine on my own domain, but not on anyone elses?

Created javascript widget. Testing on my own domain and its working fine. However when posting on a 3rd party site it looks like it's not connecting to the database and getting the data.

Here is the part of the js file where I get the data:

/******* Load HTML *******/
var jsonp_url = "http://www.example.com/widget/data.php";
$.getJSON(jsonp_url, function(data) {

When I test on example.com everyt开发者_Go百科hing is fine. I set the permissions on data.php to 777 and it still isn't working. Please help!


you cannot make an ajax call across different domains: let's say your domain is 'example.com', and the third party site has 'thirdparty.com'. you install the widget on thirdparty.com. The widget code on thirdparty.com will try to make an ajax request to 'example.com'. Which is forbidden by the browser.

You can always replace the ajax call with a straight < script > tag. This doesn't have any restriction.

Hope it helps


You have a variable called jsonp_url, but the URL you use doesn't include the string callback=? which the documentation says triggers jsonp mode.

You need to include that in the URL and make sure that your server side script is outputting JSONP (using $_GET['callback'] (with suitable sanitisation) to determine the function name you wrap the JSON in).


they need to enable cross orgin resource sharing. http://enable-cors.org/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜