繁体   English   中英

Ajax / jQuery跨域对PHP脚本的要求

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM