Javascript 从Jquery表单过帐数据
我有一个简单的jquery表单,它从用户那里获取输入,将数据发布到另一个页面,并显示一条成功消息。 但我的问题是,数据不会被发布到另一个页面,而是会弹出错误消息 以下是我的Jquery:Javascript 从Jquery表单过帐数据,javascript,jquery,asp.net,web,Javascript,Jquery,Asp.net,Web,我有一个简单的jquery表单,它从用户那里获取输入,将数据发布到另一个页面,并显示一条成功消息。 但我的问题是,数据不会被发布到另一个页面,而是会弹出错误消息 以下是我的Jquery: $(document).ready(function () { $("#register").click(function () { var name = $("#name").val(); var email = $("#email").val(); var passwor
$(document).ready(function () {
$("#register").click(function () {
var name = $("#name").val();
var email = $("#email").val();
var password = $("#password").val();
var cpassword = $("#cpassword").val();
if (name == '' || email == '' || password == '' || cpassword == '') {
alert("Please fill all fields...!!!!!!");
} else if ((password.length) < 8) {
alert("Password should atleast 8 character in length...!!!!!!");
} else if (!(password).match(cpassword)) {
alert("Your passwords don't match. Try again?");
} else {
$.ajax({
type:"POST",
url: "SignUp.aspx/register", //trying to post to this url
data: { firstName: name },
success: function (msg) {
alert("Success"); // Success message which should pop up if successful
},
error: alert("Failed") //error message which should pop up if there is an error
});
}
});
});
我提供的url是正确的,没有问题。
这里可能有什么问题
还有其他方法可以将数据发送到其他页面吗
感谢您抽出时间尝试设置ajax请求的contentType选项
contentType:'application/x-www-urlencoded; UTF-8',
我希望这能解决你的问题。这个
success: function (msg) {
alert("Success"); // Success message which should pop up if successful
},
error: alert("Failed") //error message which should pop up if there is an error
});
应该是:
success: function (msg) {
alert("Success"); // Success message which should pop up if successful
},
error: function(){alert("Failed")} //error message which should pop up if there is an error
});
不过,您可能还有其他错误。您的ajax调用格式不正确。应该是:
$.ajax({
type:"POST",
url: "SignUp.aspx/register", //trying to post to this url
data: { firstName: name })
.done(function(data)
{
alert(JSON.stringify(data));
})
.success(function (msg) {
alert("Success"); // Success message which should pop up if successful
})
.fail(function(err){
alert("Failed"); //error message which should pop up if there is an error
});
开发人员控制台可能会向您显示引发的服务器端错误。这可能是一个很好的线索。@KirkWoll No errors displayedsyntax对于错误处理程序来说是错误的,需要在函数中包装警报,并且还需要防止默认表单提交。如果这些问题没有解决,则需要在的netowrk选项卡中检查实际请求console@charlietfl我试试看,这是$.ajaxapi中的默认值……将其设置为默认值不会起任何作用
$.ajax({
type:"POST",
url: "SignUp.aspx/register", //trying to post to this url
data: { firstName: name })
.done(function(data)
{
alert(JSON.stringify(data));
})
.success(function (msg) {
alert("Success"); // Success message which should pop up if successful
})
.fail(function(err){
alert("Failed"); //error message which should pop up if there is an error
});