Simple jQuery, PHP and JSONP example?

后端 未结 7 2252
佛祖请我去吃肉
佛祖请我去吃肉 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

    More Suggestion

    JavaScript:

    $.ajax({
            url: "http://FullUrl",
            dataType: 'jsonp',
            success: function (data) {
    
                //Data from the server in the in the variable "data"
                //In the form of an array
    
            }
    
    });
    

    PHP CallBack:

     array('fullName' => 'Meni Samet', 'fullAdress' => 'New York, NY'),
         '1' => array('fullName' => 'Test 2', 'fullAdress' => 'Paris'),
    );
    
    if(isset ($_GET['callback']))
    {
        header("Content-Type: application/json");
    
        echo $_GET['callback']."(".json_encode($array).")";
    
    }
    ?>
    

提交回复
热议问题