使用ajax将表单发送到web2py函数

Post form to web2py function using ajax

本文关键字:web2py 函数 ajax 表单 使用      更新时间:2023-09-26

服务器采用web2py编写,托管于google应用引擎。我可以通过输入domain.com/index访问我的index。html我可以通过输入domain.com/register发送表单其中"register"是默认定义的函数。py

但是,在html中,我想将表单发送到服务器并获得响应,我使用具有跨域问题的ajax。所以我使用"注册"作为URL,它不起作用。帮助吗?

$("#signup").click(function() {
$.ajax({
       type: "POST",
       url: "register",
       data: $("#formsignup").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data);
       }
     });
return false; // avoid to execute the actual submit of the form.
});

通过输入domain.com/register,我可以完全触发该函数。这里的问题是什么?表单被发送到domain.com…在浏览器中显示为htt[://domain.com/?email=ada@ad.com&password=adsa

它的寄存器很可能正在寻找GET而不是POST尝试更改ajax

中的类型
$("#signup").click(function() {
$.ajax({
       type: "GET",
       url: "register",
       data: $("#formsignup").serialize(), // serializes the form's elements.
       success: function(data)
       {
           alert(data);
       }
     });
return false; // avoid to execute the actual submit of the form.
});