[英]Ajax/jQuery cross-domain reuqest to PHP Script
我是使用Ajax和jQuery的新手。 我一直在嘗試使用jQuery將表單數據發送到PhP腳本。
這是我的jQuery代碼:
alert('No errors: Form will be submitted:');
$.ajax({
url: 'http://myapplication.elasticbeanstalk.com/',
dataType: 'jsonp',
crossDomain: true,
data: {nameInput: $('#name').val()},
type: 'GET',
success: function(response) {
alert("success!"+response);
},
error: function(){
alert("fail!");
}
});
郵遞區號:
<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header("Content-Type: application/json", true);
echo "----";
$return = $_GET['name'];
echo json_decode($return);
?>
jQuery代碼在一台服務器中運行,而php在Amazon Cloud服務中運行。 我不斷從elasticbeanstalk服務器收到NS_BINDING_ABORTED錯誤,但我不知道為什么。 我已經嘗試了所有方法來解決此問題,包括在$ .ajax請求中添加跨域標頭,並通過POST進行嘗試,但到目前為止,沒有任何幫助。
任何幫助表示贊賞。
var url = "http://website.com/;
var XHR = window.XDomainRequest || window.XMLHttpRequest
var xhr = new XHR();
xhr.open('GET', url, true);
xhr.onload = function() {
$('#loadhere').html(xhr.responseText);
}
xhr.send();
<div id="loadhere"></div>
並有必要添加到所有頁面
<?php header('Access-Control-Allow-Origin: *'); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.