我在页面index.aspx中有以下代码,但它无效。
我想使用Jquery向webmethod提交姓名和电子邮件。代码正在工作,直到达到$.post
但在此之后它无效。请帮忙
$("#submit").click(function () {
var email = $("#email").val();
var name = $("#name").val();
if (email != '') {
if (validateEmail(email)) {
$.post('index.aspx/SubscriberSubmit', { name: name, email: email }, function (data) {
var newDiv = $(document.createElement('div'));
newDiv.html(data);
newDiv.dialog({ minHeight: 100, modal: true });
$("#email").val('Please Enter Your Email ID');
$("#name").val('Please Enter Your Name');
});
}
else {
var newDiv = $(document.createElement('div'));
newDiv.html('Please Enter a Valid Email ID');
newDiv.dialog({ minHeight: 100, modal: true });
$("#email").val('');
}
}
});
webmethod处于代码隐藏
[WebMethod]
public static string SubscriberSubmit(string name, string email)
{
return "hello";
}
请建议我错在哪里
答案 0 :(得分:0)
如果你有
<input id="submit" type="submit"/>
或
<button id="submit"></button>
发送帖子请求,处理提交和页面重新加载后点击,所以只需更改你的标记
<input id="submit" type="button"/>
<button id="submit" type="button"></button>