dppx9253 2017-03-08 12:49
浏览 75
已采纳

在每个Ajax调用上重新加载调用页面

I need a page called via ajax to fully reload everytime I request it. Currently, when requested for the first time it loads the page correctly, but when requested the second time it loads with the previous result and then after 2 or 3 second loads the new result.

I want it to show a loading image while it reloads the page into my div.

See code I'm using below:

$io('#load_order_preview').on('click', function(){

            var portfolioName       = $io("#portfolioName").val();
            var instrumentType      = $io("#instrumentType").val();
            var securityName        = $io("#securityName").val();
            var orderType           = $io("#orderType").val();
            var priceType           = $io("#priceType").val();
            var quantityRequested   = $io("#quantityRequested").val();
            var orderTermName       = $io("#orderTermName").val();
            var limitPrice          = $io("#limitPrice").val();
            var stockPrice          = $io("#stockPrice").val();
            var stopPrice           = $io("#stopPrice").val();

            var dataString = 'portfolioName='+ portfolioName + '&instrumentType=' + instrumentType + '&securityName=' + securityName + '&orderType=' + orderType + '&priceType=' + priceType + '&quantityRequested=' + quantityRequested + '&orderTermName=' + orderTermName + '&limitPrice=' + limitPrice + '&stopPrice=' + stopPrice;

             $io('#load_popup_modal_orderpreview').load(
                 'load-preview.php?' + dataString
             }).modal({
             backdrop: 'static',
             keyboard: false
             }).show();

        });

I'd really like some help to solve this problem.

Thanks in advance.

  • 写回答

1条回答 默认 最新

  • duanditang2916 2017-03-08 13:02
    关注

    try this, not sure it will work for regular javascript,

         $io('#load_order_preview').on('click', function(){
    
    var dataString = 'portfolioName='+ portfolioName + '&instrumentType=' + instrumentType + '&securityName=' + securityName
                        + '&orderType=' + orderType + '&priceType=' + priceType + '&quantityRequested=' + quantityRequested
                        + '&orderTermName=' + orderTermName + '&limitPrice=' + limitPrice + '&stopPrice=' + stopPrice;
    
                     $io('#load_popup_modal_orderpreview').load(
                         'load-preview.php?' + dataString
                     }).modal({
                     backdrop: 'static',
                     keyboard: false,
    cache: false
                     }).show();
    
    });
    

    basically your problem is of cache, when you reload the page, it took values from cache and when you reload 2-3 times it fetch forcefully from server.

    Edit ==

    If cache is not your prob, and since it took 2-3 sec to reflect new images, it is prob with async behavior of browser. When you make request, browser will not wait for your response and move ahead, when it will receive response it will act on it.

    Solution,

    try to make ajax call and on success response do your activity

    or

    (last option and not good practice) Make your call async false,

     $io('#load_order_preview').on('click', function(){
    
    var dataString = 'portfolioName='+ portfolioName + '&instrumentType=' + instrumentType + '&securityName=' + securityName
                        + '&orderType=' + orderType + '&priceType=' + priceType + '&quantityRequested=' + quantityRequested
                        + '&orderTermName=' + orderTermName + '&limitPrice=' + limitPrice + '&stopPrice=' + stopPrice;
    
                     $io('#load_popup_modal_orderpreview').load(
                         'load-preview.php?' + dataString
                     }).modal({
                     backdrop: 'static',
                     keyboard: false,
    cache: false,
    async: false
                     }).show();
    
    });
    

    note this will make your browser wait till your server respond to your call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算