douchen5971 2012-12-22 05:37
浏览 43
已采纳

用jquery和ajax根据州改变城市

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

  • 写回答

3条回答 默认 最新

  • dongli8862 2012-12-22 05:44
    关注

    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);
    });

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料