![](/img/trans.png)
[英]xmla4js I keep getting Origin null is not allowed by Access-Control-Allow-Origin ajax header
[英]Posting form with Ajax to a different server getting is not allowed by Access-Control-Allow-Origin error
$this->output->set_header("Access-Control-Allow-Origin: *");
該行似乎可以通過ajax從另一台服務器訪問頁面,但是當我嘗試將數據發布到另一台服務器時,即使上面的行在我的腳本中,我仍然遇到錯誤。
這是我用來發布數據的Ajax。
$.ajax({
url: "' . base_url('pagehere') . '",
type: "POST",
data: "type=pform&ip="+ip+"&host_server="+host_server+"&mediabar="+mediabar+fields,
success: function(msg) {
$("#panelform").hide();
$(".pthankyou").show();
}
});
這是我要發布到的頁面上的內容:
$this->output->set_header("Access-Control-Allow-Origin: *");
$this->output->set_header("Access-Control-Allow-Methods: POST");
我不確定要完成這項工作還需要什么。
您必須使用憑證設置ajax:
$.ajax({...
xhrFields:{
withCredentials: true
},
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.