[英]cross domain ajax call + php
I want to get data from the webservices through jquery ajax call(cross domain). 我想通过jquery ajax调用(跨域)从Web服务获取数据。 After fetching data from webservices, i need to show it as a dataTable using php.
从Web服务获取数据后,我需要使用php将其显示为dataTable。 Can anyone help me regarding this or just give me some sampe examples.
有人可以帮我这个忙吗,还是给我一些例子。
my ajax function is as follows: 我的ajax函数如下:
$.ajax({
type: "POST",
url:"my webservice url",
//data: json,
//contentType: "application/json; charset=utf-8",
crossDomain: true,
dataType: 'json',
async:false,
success: function(data, textStatus, jqXHR)
{
alert("Download success");
alert(data);
},
error : function(jqXHR, exception)
{
alert(jqXHR.status);
}
});
$.ajax({
url:"yourPageName.php",
dataType: 'jsonp', // N.B! JSONP It is lower Case OK?
success:function(json){
// json (an Array)
alert("Success");
},
error:function(){
alert("Error");
},
}); });
For more info please visit here http://api.jquery.com/jQuery.ajax/ 有关更多信息,请访问此处http://api.jquery.com/jQuery.ajax/
Jsonp is better way to do it. Jsonp是更好的方法。 But if you really do with json you can add
但是,如果您确实使用json,则可以添加
header("Access-Control-Allow-Origin: *");
to your php code. 到您的php代码。 This way your server will response any request and domain.
这样,您的服务器将响应任何请求和域。 You can customize "*" to accept domain.
您可以自定义“ *”以接受域。 But be aware this will cause security issue.
但是请注意,这将导致安全问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.