我想知道jquery中$ .ajax和$ .post之间的区别。 我搜索它但没有得到澄清。 实际上我正在下降州和城市,当州改变jquery $ .post时我正在改变城市。 这是我的jquery代码
$.post('includes/change_cities.php', { 'state_id': state_id }, function( data ) { var content = $( data ); $( "#cities" ).empty().append( content ); } );我的问题是当州第一次改变时需要花费太多时间来改变城市大约4到5秒,但是在第一次改变之后它变得正常意味着改变城市而不花时间。 那么我的代码中是否有任何问题,或者我应该使用任何其他方法。
-谢谢
I want to know difference between $.ajax and $.post in jquery. I search it but not getting clearification. Actually I am having drop down of states and cities and I am changing cities when states changes with jquery $.post. Here is my code of jquery
$.post('includes/change_cities.php', { 'state_id': state_id }, function( data ) { var content = $( data ); $( "#cities" ).empty().append( content ); } );My Problem is when states changes for the first time it takes too much time to change cities about 4 to 5 seconds but after first time it becomes normal means changes cities without taking any time. So Is there any problem in my code or should I use any other method for this.
-Thanks
最满意答案
性能取决于您的代码和SQL实现。 $ .post是功能tersm中$ .ajax的子集。
$就({ 输入:'POST' , url:'ajax / test.html', 数据:数据, 成功:函数(数据){ $( '结果')。HTML(数据) }, });
相当于
$ .post('ajax / test.html',function(data){ $( '结果')HTML(数据)。 });
The performance Depends on your code and sql implementation. $.post is subset of $.ajax in tersm of functionality.
$.ajax({ type: 'POST', url: 'ajax/test.html', data: data, success: function(data){ $('.result').html(data) }, });
is Equivalent to
$.post('ajax/test.html', function(data) { $('.result').html(data); });
更多推荐
发布评论