更新.....
我是JQuery的新手,我坚持这一点,并希望有人可以帮助我。我想要做的是刷新DIV中的数据而不重新加载整个页面。因为页面很大,我试图总结一下。
--- This form is right after the body, not wrab with DIV or anything, no submit button. I want to submit the value in the textbox when user hit ENTER key.
<form name="form1" id="form1" method="post" action="PurchaseRequestList.asp">
<input type="text" name="CompanyName" id="CompanyName" value="" class="box2">
</form>
--- Below the form is the DIVs, where I like to refresh the data everytime user enter in the CompanyName textbox and hit Enter key.
<div id="div1-wrapper">
<div id="div1" style="border:solid 1px red; width: 100%;">
<table width="90%" align="center" class="RowDetail">
<-- This is where the loop using ASP to display the data -->
</table>
</div>
</div>
到目前为止,我有这段代码,但它不能作为DIV中的仅刷新数据。
$(document).ready(function() {
$('#CompanyName').on('keypress', function(e) {
if (e.keyCode == 13)
{
var data = $('form').serialize();
$.ajax({
method: 'post',
data: data,
url: 'PurchaseRequestList.asp?#div1',
success: function(res) {
$('#div1-wrapper').load(url + ' #div1');
}
});
}
});
});
我感谢你们,我们正在努力提供帮助。如果您需要我澄清,请告诉我。
谢谢,
答案 0 :(得分:0)
试试此代码
var url = 'PurchaseRequestList.asp?order=1';
$( "form" ).on( "submit", function( event ) {
event.preventDefault();
var data = $( this ).serialize();
$.ajax({
method: 'post',
data: data,
url: url + '?#div1',
success: function(res) {
$('#div1-wrapper').load(res);//u need to change here
}
});
});
或
$('#CompanyName').on('keypress', function(e) {
if (e.keyCode == 13)
{
var data = $('form').serialize();
$.ajax({
method: 'post',
data: data,
url: url + '?#div1',
success: function(res) {
$('#div1-wrapper').load(res);
}
});
}
});