重新加载 div 点击和 post 数据的最佳做法
Best practice to reload div on click and post data
我在 jQuery 方面不是最出色的,并且仍在学习零碎知识。我目前有以下功能,我想将其扩展到 post 数据到 referrer-ajax2.php
.
$(document).ready(function() {
$('#clickthrough').click(function(){
$('#declined').load('referrer-ajax2.php #declined2');
});
});
我可以添加另一个功能吗,例如:
$(document).ready(function() {
$('#clickthrough').click(function(){
$('#declined').load('referrer-ajax.php2 #declined2', function() {
$.post('referrer-ajax.php2', { company_selected: $('#refselect').val(), ref_date_from: $('#ref_date_from').val(), ref_date_to: $('#ref_date_to').val() },
});
});
});
这是正确的做法还是有更明智的做法?这不会重新加载 div 然后 post 数据(这将是错误的方式)我假设我可以切换函数吗?
还没有真正尝试过任何东西,只是想了解正确的方法并发展我对 jQuery 的了解。
感谢你们的意见。
是的,您可以添加它,但它应该先 post,然后加载。 Buf 如果您想在 post 之后显示特定内容,只需发送您想要显示的内容,不要再次请求(加载)以获取更新的内容。
我在 jQuery 方面不是最出色的,并且仍在学习零碎知识。我目前有以下功能,我想将其扩展到 post 数据到 referrer-ajax2.php
.
$(document).ready(function() {
$('#clickthrough').click(function(){
$('#declined').load('referrer-ajax2.php #declined2');
});
});
我可以添加另一个功能吗,例如:
$(document).ready(function() {
$('#clickthrough').click(function(){
$('#declined').load('referrer-ajax.php2 #declined2', function() {
$.post('referrer-ajax.php2', { company_selected: $('#refselect').val(), ref_date_from: $('#ref_date_from').val(), ref_date_to: $('#ref_date_to').val() },
});
});
});
这是正确的做法还是有更明智的做法?这不会重新加载 div 然后 post 数据(这将是错误的方式)我假设我可以切换函数吗?
还没有真正尝试过任何东西,只是想了解正确的方法并发展我对 jQuery 的了解。
感谢你们的意见。
是的,您可以添加它,但它应该先 post,然后加载。 Buf 如果您想在 post 之后显示特定内容,只需发送您想要显示的内容,不要再次请求(加载)以获取更新的内容。