英特尔 XDK Ajax 上传到服务器后不允许访问 [在 xampp 中运行良好]
Intel XDK Ajax Access not allowed after uploading to server [working good in xampp]
我正在构建一个 XDK 应用程序,
在 xampp 中运行良好并修复了 header 问题,在上传到实时服务器后 ajax 调用不起作用,我收到此错误
XMLHttpRequest cannot load http://watanydemo.eb2a.com/metawe3/action/get?_=1451186106865. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
index.html:92 {"readyState":0,"status":0,"statusText":"error"}
尽管我通过各种方式设置了 header,但原点仍然设置为 null
public function get()
{ $this->load->model('Name_model');
$result = $this->Name_model->read_names();
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
echo json_encode($result);
}
注意我的后端是 Codeigniter
我的Ajax电话是
<script type="text/javascript">
$(document).ready(function() {
$('#loading-image').show();
try {
$.ajax({
type: "GET",
url: "http://watanydemo.eb2a.com/metawe3/action/get",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
async: true,
dataType: 'json',
processData: false,
cache: false,
success: function (response) {
alert("valid response");
for (var i = 0, res = response.length; i < res; ++i) {
var picture = response[i].picurl;
var name= response[i].name;
$("#row").append('<div class="col-md-4"><h1>'+name+'</h1><img id="pic" class="thumbnail img-responsive" alt="Bootstrap template"src="'+picture+'" />'+'<div class="well"></div></div>');
}
},
complete: function(){
$('#loading-image').hide();
},
error: function (ErrorResponse) {
console.log(JSON.stringify(ErrorResponse));
}
});
}
catch (error) {
console.log(JSON.stringify(error));
}
});
</script>
问题出在服务器上的 PHP 版本中,当我用新的 PHP 版本更改服务器时,一切正常并且 运行!
我正在构建一个 XDK 应用程序, 在 xampp 中运行良好并修复了 header 问题,在上传到实时服务器后 ajax 调用不起作用,我收到此错误
XMLHttpRequest cannot load http://watanydemo.eb2a.com/metawe3/action/get?_=1451186106865. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
index.html:92 {"readyState":0,"status":0,"statusText":"error"}
尽管我通过各种方式设置了 header,但原点仍然设置为 null
public function get()
{ $this->load->model('Name_model');
$result = $this->Name_model->read_names();
header('Access-Control-Allow-Origin: *');
header('Content-type: application/json');
echo json_encode($result);
}
注意我的后端是 Codeigniter
我的Ajax电话是
<script type="text/javascript">
$(document).ready(function() {
$('#loading-image').show();
try {
$.ajax({
type: "GET",
url: "http://watanydemo.eb2a.com/metawe3/action/get",
crossDomain: true,
contentType: "application/x-www-form-urlencoded",
async: true,
dataType: 'json',
processData: false,
cache: false,
success: function (response) {
alert("valid response");
for (var i = 0, res = response.length; i < res; ++i) {
var picture = response[i].picurl;
var name= response[i].name;
$("#row").append('<div class="col-md-4"><h1>'+name+'</h1><img id="pic" class="thumbnail img-responsive" alt="Bootstrap template"src="'+picture+'" />'+'<div class="well"></div></div>');
}
},
complete: function(){
$('#loading-image').hide();
},
error: function (ErrorResponse) {
console.log(JSON.stringify(ErrorResponse));
}
});
}
catch (error) {
console.log(JSON.stringify(error));
}
});
</script>
问题出在服务器上的 PHP 版本中,当我用新的 PHP 版本更改服务器时,一切正常并且 运行!