本文介绍了JQuery的Ajax表单提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
不知道是什么原因发生这种情况,但在点击一个按钮,我称之为一个jQuery的Ajax控制,之后我就不想继续提交表单,但在此之前的页面仍然被提交。
< ASP:ImageButton的ID =btnContinue的OnClick =btnContinue_Click=服务器的OnClientClick =返回false; />
和jQuery的:
$(#<%= btnContinue.ClientID%>中)。点击(函数(){
VAR currentpickupLocation =的document.getElementById(<%= ddlPickupLocation.ClientID%>中)值。
VAR currentpickupDate =的document.getElementById(<%= txtPickupDate.ClientID%>中)。值;
变种的CurrentCulture =&其中;%= GetCulture()%>中;
变种PARAMS = $ .toJSON({pickupLocation:currentpickupLocation,pickupDate:currentpickupDate});
$阿贾克斯({
键入:POST,
网址:LocationService.asmx / GetBlackoutDates
数据:参数,可以
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON,
成功:函数(位置){
返回false;
}
});
});
解决方案
您需要有一个回虚假的点击区域,像这样:
$(#<%= btnContinue.ClientID%>中)。点击(函数(){
VAR currentpickupLocation =的document.getElementById(<%= ddlPickupLocation.ClientID%>中)值。
VAR currentpickupDate =的document.getElementById(<%= txtPickupDate.ClientID%>中)。值;
变种的CurrentCulture =&其中;%= GetCulture()%>中;
VAR PARAMS = $ .toJSON({
pickupLocation:currentpickupLocation,
pickupDate:currentpickupDate
});
$阿贾克斯({
键入:POST,
网址:LocationService.asmx / GetBlackoutDates
数据:参数,可以
的contentType:应用/ JSON的;字符集= UTF-8,
数据类型:JSON,
成功:函数(位置){
返回false;
}
});
返回false; //这告诉浏览器不提交
});
Not exactly sure why this is happening, but upon click of a button I call a JQuery Ajax control, after that I do not want to continue submitting the form, but before the page gets still submitted.
<asp:ImageButton id="btnContinue" OnClick="btnContinue_Click" runat="server" OnClientClick="return false;" />
and the jQuery:
$("#<%=btnContinue.ClientID%>").click(function() {
var currentpickupLocation = document.getElementById("<%=ddlPickupLocation.ClientID %>").value;
var currentpickupDate = document.getElementById("<%=txtPickupDate.ClientID %>").value;
var currentCulture = "<%= GetCulture() %>";
var params = $.toJSON({pickupLocation: currentpickupLocation, pickupDate: currentpickupDate});
$.ajax({
type: "POST",
url: "LocationService.asmx/GetBlackoutDates",
data: params,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(locations) {
return false;
}
});
});
解决方案
You need to have a return false in the click area like so:
$("#<%=btnContinue.ClientID%>").click(function() {
var currentpickupLocation = document.getElementById("<%=ddlPickupLocation.ClientID %>").value;
var currentpickupDate = document.getElementById("<%=txtPickupDate.ClientID %>").value;
var currentCulture = "<%= GetCulture() %>";
var params = $.toJSON({
pickupLocation: currentpickupLocation,
pickupDate : currentpickupDate
});
$.ajax({
type: "POST",
url: "LocationService.asmx/GetBlackoutDates",
data: params,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(locations) {
return false;
}
});
return false; //this tells the browser not to submit
});
这篇关于JQuery的Ajax表单提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!