I am facing a problem in ajax jquery on success. My whole jsp reload on ajax success even after putting return false. How to prevent page reloading.
我在ajax jquery中遇到了一个成功的问题。我的整个jsp重载了ajax的成功,即使输入了return false。如何防止页面重载。
function AjaxCall(category){
var formValue = $('#TP').serialize();
$.post('saveIndvQuestionnaire.jsp?'+formValue+'&category='+category,
//$.post('callPage.jsp',
function(data) {
return false;
});
}
I am calling AjaxCall function from input type image
我从输入类型映像调用AjaxCall函数
<input id="test" type="image" onclick="javascript:AjaxCall('Test');" src="../images/v10/larrow.png">
I am not sure I read somewhere type images makes two calls onclick.
我不确定我在什么地方读到什么类型的图像在点击时会发出两次调用。
Thanks.
谢谢。
3 个解决方案
#1
1
Perhaps the problem is the behavior of input type image. https://developer.mozilla.org/es/docs/Web/HTML/Element/Input Try to use e.preventDefault() in your function and no Submit should be done.
也许问题在于输入类型图像的行为。https://developer.mozilla.org/es/docs/Web/HTML/Element/Input尝试在函数中使用e.preventDefault(),不应该提交。
$( "#test" ).click(function( event ) {
event.preventDefault();
var formValue = $('#TP').serialize();
$.post('saveIndvQuestionnaire.jsp?'+formValue+'&category='+category,
function(data) {
return false;
});
});
Exmple
东西
http://jsfiddle.net/HBeVv/10/
You can use another html control to achieve this like a href with a Image:
您可以使用另一个html控件来实现类似于href的图像:
<a href="#" onClick="alert('Hello World!')"><img title="The Link" /></a>
#2
1
I think you can also Like this
我想你也可以喜欢这个
$('YourForm').submit(function(e){
e.preventDefault();
formdata=$(this).serialize();
$.ajax({
type: "POST",
url: url,
data: formdata
}).done(function(data){
//do something
});
});
#3
1
Try this:
试试这个:
<input id="test" type="image" onclick="return javascript:AjaxCall('Test');" src="../images/v10/larrow.png">
You should get "return" the response onclick.
您应该在单击时获得“返回”响应。
#1
1
Perhaps the problem is the behavior of input type image. https://developer.mozilla.org/es/docs/Web/HTML/Element/Input Try to use e.preventDefault() in your function and no Submit should be done.
也许问题在于输入类型图像的行为。https://developer.mozilla.org/es/docs/Web/HTML/Element/Input尝试在函数中使用e.preventDefault(),不应该提交。
$( "#test" ).click(function( event ) {
event.preventDefault();
var formValue = $('#TP').serialize();
$.post('saveIndvQuestionnaire.jsp?'+formValue+'&category='+category,
function(data) {
return false;
});
});
Exmple
东西
http://jsfiddle.net/HBeVv/10/
You can use another html control to achieve this like a href with a Image:
您可以使用另一个html控件来实现类似于href的图像:
<a href="#" onClick="alert('Hello World!')"><img title="The Link" /></a>
#2
1
I think you can also Like this
我想你也可以喜欢这个
$('YourForm').submit(function(e){
e.preventDefault();
formdata=$(this).serialize();
$.ajax({
type: "POST",
url: url,
data: formdata
}).done(function(data){
//do something
});
});
#3
1
Try this:
试试这个:
<input id="test" type="image" onclick="return javascript:AjaxCall('Test');" src="../images/v10/larrow.png">
You should get "return" the response onclick.
您应该在单击时获得“返回”响应。