jquery获取页面后端数据。要用到Ajax。设置个button,点击button就能显示所需要提取的页面数据。

2025-01-18 20:13:42
推荐回答(5个)
回答1:

function getData()
{
    $.ajax({ 
        type:"get", 
        url:"10.16.61.60:90/solr/core2/select?q=phrase:hard%20drive&wt=json&indent=true&rows=6&start=5 ",
        dataType: "json", 
        data:{zip:Math.random()},
        success:function(result){
              if(result.status==0){ 
                    $.each($(result.response.docs),function(i,n){ 
                         var index=n.index;
                         var phrase=n.phrase; 
                    }); 
              }
        }    
    });  
}

回答2:

比如你接收到的数据为data,
然后就是循环数据var arr=data.response.docs;var _html='';
for(var i=0,len=arr.length;ivar nindex=arr[i]["index"];

var phrase=arr[i]["phrase"];
_html+='

index='+nindex+',phrase='+phrase+'
';

}
然后把_html加入的想要放的dom中。原理大概就这样的。

回答3:

$.ajax({
url:"10.16.61.60:90/solr/core2/select?q=phrase:hard%20drive&wt=json&indent=true&rows=6&start=5",
dataType:"JSON",
type:"GET",
success:function(res){
//拿到需要用到数据集,
var resList = res.response.docs;
//拼接数据渲染到html
var tpl = "";
resList.forEach(function(item){
tpl+="
"+item.index+"
"+item.phrase+"
"+"
"+item._version_+"
"
$("#id").html(tpl);
);
});
},
error:function(err){
console.log("错误:"+err);
}
});

回答4:



$('#btn').click(function(){
    var url = 'index.php';
    var data=('#btn').val();
    $.ajax({
        type: 'post',
        url: url ,
        data: {
            data:data    
        } ,
        cache:false,  
        dataType:'json',
        success: function(result){
         if(result){ 
            console.log(result); 
                  }else{  
                    console.log(result);  
                  }  
        },
        error : function() {  
23                 console.log("error");
25              }  
    });
})

回答5:

function getData()
{
$.ajax({
type:"get",
url:"10.16.61.60:90/solr/core2/select?q=phrase:hard%20drive&wt=json&indent=true&rows=6&start=5 ",
dataType: "json",
data:{zip:Math.random()},
success:function(result){
if(result.status==0){
$.each($(result.response.docs),function(i,n){
var index=n.index;
var phrase=n.phrase;
});
}
}
});
}