用jquery和ajax根据州改变城市(changing cities according to states with jquery and ajax)

编程入门 行业动态 更新时间:2024-10-27 05:36:25
用jquery和ajax根据州改变城市(changing cities according to states with jquery and ajax)

我想知道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); });

更多推荐

本文发布于:2023-07-30 07:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1336752.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:城市   ajax   jquery   states   cities

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!