开发者

Want to call https request using jquery

Suppose I have a server at this URL: https://example.com/employee, and its returns JSON data. I want to retrieve this data using Jquery on iPhone. I wrote this code :

 $.ajax {
   type: "POST",          
   contentType: "application/json; charset=utf-8",  
   url: "https://example.com/employee",   
   data: "{}",     
   dataType: "json"   
success: function(res) {

}
});

Is this the right way to make this HTTPS request, or I need to do some other authentication also? Currently it does not work on iPhone.

It returns JSON data in Firefox, Chro开发者_运维技巧me, IE, Safari, but it doesn't return anything on iPhone.


What are you trying to do is JSON, not JSONP. This restriction is called Same Origin Policy

Try this

 $.ajax {
   type: "POST",          
   contentType: "application/json; charset=utf-8",  
   url: "https://example.com/employee?callback=?",   
   data: "{}",     
   dataType: "json"   
success: function(res) {

}
});

and in that server-side script use something like

<?php

    echo preg_replace("/</i", "", $_GET['callback'])."(".$your_data.")";
?>

and it should work ;)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜