Simple jQuery, PHP and JSONP example?

后端 未结 7 2184
佛祖请我去吃肉
佛祖请我去吃肉 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 17:15

    Use this ..

        $str = rawurldecode($_SERVER['REQUEST_URI']);
        $arr = explode("{",$str);
        $arr1 = explode("}", $arr[1]);
        $jsS = '{'.$arr1[0].'}';
        $data = json_decode($jsS,true);
    

    Now ..

    use $data['elemname'] to access the values.

    send jsonp request with JSON Object.

    Request format :

    $.ajax({
        method : 'POST',
        url : 'xxx.com',
        data : JSONDataObj, //Use JSON.stringfy before sending data
        dataType: 'jsonp',
        contentType: 'application/json; charset=utf-8',
        success : function(response){
          console.log(response);
        }
    }) 
    
    0 讨论(0)
提交回复
热议问题