访问 Jquery/AJAX 发送的 $_POST 数据
我正在使用此函数:
function end_incident() {
var dataString = 'name=Daniel&phone=01234123456';
$.ajax({
type: "POST",
url: "http://www.example.co.uk/erc/end_incident.php",
data: dataString,
success: function(msg){
alert('Success!'+dataString);
}
});
};
将信息发送到 end_incident.php
,但我无法访问 $_POST
变量。我尝试过这样做:
$name = $_POST['name'];
$phone = $_POST['phone'];
我做错了什么吗?
感谢您的帮助
I am using this function:
function end_incident() {
var dataString = 'name=Daniel&phone=01234123456';
$.ajax({
type: "POST",
url: "http://www.example.co.uk/erc/end_incident.php",
data: dataString,
success: function(msg){
alert('Success!'+dataString);
}
});
};
to send information to end_incident.php
, but I'm not able to access the $_POST
variables. I've tried doing it like this:
$name = $_POST['name'];
$phone = $_POST['phone'];
Am I doing something wrong?
Thanks for any help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将数据作为对象发送:
Try sending the data as an object:
确保您请求的网址与您的网站同源,如果不是,则说明您遇到了跨站点脚本问题。唯一的解决方法是:
通过您自己的站点使用代理来获取文件请求:
我建议您向 ajax 添加一个
error
函数。令人惊讶的是,有多少人只关注成功
而从不处理错误!Make sure the url your requesting for is within the same origin of your site, if it isn't, you've got a cross-site scripting issue. Only way around that:
Use a proxy through your own site to get the request for the file:
I recommend you add a
error
function to your ajax. It's suprising how many people just focus onsuccess
and never process an error!