如何在新页面上显示AJAX响应

时间:2014-12-10 16:11:53

标签: jquery ajax

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

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>

1 个答案:

答案 0 :(得分:0)

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

$.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();

    }

});