Im sending and receiving posts with ajax and php, now when would be the best time to update my response to my html, after send post or before?
我发送和接收带有ajax和php的帖子,现在什么时候是发送帖子之后或之前更新我对html的回复的最佳时间?
1 个解决方案
#1
1
It depends.
这取决于。
The most common approach I have used/seen is to update your HTML after you receive a response from the PHP script you are executing via AJAX.
我使用/看过的最常见的方法是在从通过AJAX执行的PHP脚本收到响应后更新HTML。
jQuery example:
jQuery示例:
$.post('script.php', {name_1: value_1, name_2: value_2}, function(data){
/*
this is the function that is fired upon a successful AJAX execution
the data variable contains the data script.php outputs
*/
//update html here
});
#1
1
It depends.
这取决于。
The most common approach I have used/seen is to update your HTML after you receive a response from the PHP script you are executing via AJAX.
我使用/看过的最常见的方法是在从通过AJAX执行的PHP脚本收到响应后更新HTML。
jQuery example:
jQuery示例:
$.post('script.php', {name_1: value_1, name_2: value_2}, function(data){
/*
this is the function that is fired upon a successful AJAX execution
the data variable contains the data script.php outputs
*/
//update html here
});