PHP: Handling 'JSONP' output vs 'JSON', and its parsing?

后端 未结 3 857
遇见更好的自我
遇见更好的自我 2021-01-18 13:49

I am having a problem parsing \'jsonp\' request with php\'s json_decode function.

My questions is

a. What is the u

3条回答
  •  误落风尘
    2021-01-18 14:24

    Callback function is for JS calls - it allows to use API's in AJAX manner, without taking care of same origin policy. When JSONP call is used in JS - browser just calls the callback function that needs to be defined on API client's side.

    When you use JSONP inside PHP callback function is not needed at all. If server supports raw JSON type calls - use it, if not strip the callback function strings, in your case

    $jsonData = json_decode(substr($feed, 22, -2));
    

提交回复
热议问题