因此,我使用 Ajax 将表单发布到服务器,但是,它不是将表单发送到 URL,而是发送到自身。
这是代码
$("#psignup").click(function() {
$.ajax({
type: "POST",
url: "example/default/mobile_user_register",
data: $("#patientsignup").serialize(), // serializes the form's elements.
success: function(data)
{
alert(data); // show response from the php script.
}
});
return false; // avoid to execute the actual submit of the form.
});
在浏览器中,它似乎将发件人发送到 http://localhost:8080/?email=asdfa%40asd.com&password=asd&repeatpassword=&firstname=asd&username=&lastname=asd
我要找的当然是“http://example.com/default/mobile_user_register?xxxxxxxxxxxxxx ”。你能帮我理解为什么这不起作用吗?
最佳答案
使用JSONP
$.ajax({
url: "http://example.com/default/mobile_user_register?xxxxxxxxxxxxxx",
dataType: 'jsonp', //use jsonp data type in order to perform cross-domain ajax
crossDomain: true,
data: data,
success: callback,
error: callback
});
关于javascript - 为什么 Ajax 将数据发布到 localhost 而不是提供的 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16446702/