如何在新页面上显示AJAX响应 [英] How to show AJAX response on new page

查看:62
本文介绍了如何在新页面上显示AJAX响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用phonegap开发移动应用程序并使用intel xdk,我想在我在google上搜索并找到此解决方案的新html页面上显示ajax响应window.open();,但此方法对我不起作用并显示空白(白屏).我想在我的search.html页面中显示数据,并且我正在使用jquery和ajax从数据库获取响应.

I'm developing mobile app in phonegap and using intel xdk and i want to show ajax response on new html page I have searched on google and found this solution window.open(); but this method does not work for me and show blank (white screen). I want to show the data in my search.html page and I'm using jquery and ajax for getting response from database.

function search() {
    $("#LoadingImage").show();
    var valuee=document.querySelector('input[name="srch_type"]:checked').value;
    var srch_txt = $("#search-2").val();
    if(srch_txt.length>0){
       $.ajax({
              url: "http://medicomall.com/andapp/?srchtxt="+srch_txt+"&srchtyp="+valuee,
              dataType: 'json',
              success: function(opt) {
                 $("#LoadingImage").hide();                                          
                 $.each(opt.waleed, function(key, value){   
                       //  alert( "SUCCESS:  " + value );         
                       if(valuee=='Medicine'){                   
                            $("ul").html ("<li>"+this['med_name']+"</li>"+"<li>"+this['med_alter']+"</li><a>"+this['Store_Address']+"</a><br>");
                       }else if(valuee=='Doctor'){        
                            $("ul").html("<li>"+this['name']+"</li><li>"+this['desc']+"</li>");
                      }  
                 else{
                     $("ul").html("<li>"+this['cl_name']+"</li><li>"+this['cl_address']+"</li>");   
                 }
            });  
          },
           error: function () {
               alert('Network error has occurred please try again!');
               $("#LoadingImage").hide();

            }     

        });   
   } else{
            alert("Please Enter Some Value");
            $("#LoadingImage").hide();     
         }
     }

  </script>

推荐答案

创建新窗口时,请使用以下命令:

When you create the new window use the following:

$.ajax({
    url: "http://medicomall.com/andapp/?srchtxt=" + srch_txt + "&srchtyp=" + valuee,
    dataType: 'json',
    success: function (opt) {
        $("#LoadingImage").hide();

        //Window Settings
        var w = window.open();
        //Append Search unordered list
        $(w.document.body).html('<ul class="search"></ul>');

        $.each(opt.waleed, function (key, value) {
            //  alert( "SUCCESS:  " + value );         
            if (value == 'Medicine') {
                $(w.document.body+" .search").html("<li>" + this['med_name'] + "</li>" + "<li>" + this['med_alter'] + "</li><a>" + this['Store_Address'] + "</a><br>");
            } else if (value == 'Doctor') {
                $(w.document.body+" .search").html("<li>" + this['name'] + "</li><li>" + this['desc'] + "</li>");
            } else {
                $(w.document.body+" .search").html("<li>" + this['cl_name'] + "</li><li>" + this['cl_address'] + "</li>");
            }
        });
    },
    error: function () {
        alert('Network error has occurred please try again!');
        $("#LoadingImage").hide();

    }

});

这篇关于如何在新页面上显示AJAX响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆