Simple jQuery, PHP and JSONP example?

后端 未结 7 2191
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 16:36

I am facing the same-origin policy problem, and by researching the subject, I found that the best way for my particular project would be to use JSONP to do cross-origin requ

7条回答
  •  心在旅途
    2020-11-22 16:56

    When you use $.getJSON on an external domain it automatically actions a JSONP request, for example my tweet slider here

    If you look at the source code you can see that I am calling the Twitter API using .getJSON.

    So your example would be: THIS IS TESTED AND WORKS (You can go to http://smallcoders.com/javascriptdevenvironment.html to see it in action)

    //JAVASCRIPT
    
    $.getJSON('http://www.write-about-property.com/jsonp.php?callback=?','firstname=Jeff',function(res){
        alert('Your name is '+res.fullname);
    });
    
    //SERVER SIDE
      
    

    Note the ?callback=? and +res.fullname

提交回复
热议问题