1

所以我使用 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.
});

在浏览器中,它似乎将 from 发送到http://localhost:8080/?email=asdfa%40asd.com&password=asd&repeatpassword=&firstname=asd&username=&lastname=asd

我正在寻找的当然是“ http://example.com/default/mobile_user_register?xxxxxxxxxxxxxxx ”。你能帮我理解为什么这不起作用吗?

4

4 回答 4

2

使用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
});
于 2013-05-08T17:54:51.277 回答
0

不能使用 javascript AJAX 发布到另一个 URL --> 大多数浏览器都会阻止它。

于 2013-05-08T17:28:27.247 回答
0

If I understand you correctly and the domain where this code is hosted is example.com but you're trying to call example.net, then AJAX security explicitly prohibits this.

What you'll need to do is to set up a tiny cgi proxy on your server that takes the call you want to make, and fetches that data and brings it back to you.

Assuming you were using PHP, your call will look like myProxy.php?destination=http://example.net/whatever

The proxy would then go fetch what it found at that destination and deliver it back in the response.

于 2013-05-08T17:29:38.647 回答
-6

它不会神奇地知道那example/default/mobile_user_register是您的域名。尝试http://example.com/default/mobile_user_register

于 2013-05-08T17:28:51.990 回答