ajax页面传参 json数据渲染页面

ajax在两个页面之间进行传参操作一个页面获取值 并将获取的值 通过ajax传递到后台  并将数据返回的数据进行后台渲染

参数传递

$.ajax({
type : "post",
url : "Selectphone.do",
data : {"phone":phoneAndName},
success : function(data){
if(data == "list"){
  var ph = $("#phoneAndName").val();
  var url = encodeURI("express_sn.do?id="+ph);
  var enurl = encodeURI(url);//使用了两次encodeRUI进行编码
window .location=enurl;
//上面的是只传递一个参数 下面是多个参数传递
//          链接地址     参数一    参数 参数2    参数
var uri = "express_sn.do?orders="+data[index].expressSn+"&tell="+data[index].tell+"&exp="+data[index].express+"&names="+data[index].username+"&id="+data[index].id;
var uricode = encodeURI(uri);
//跳转                  参数
$("#succ").attr('href',uricode);
}else{
alert(data);
}
 
}

});


接收参数 并在此查询数据
//接收多个参数
function GetQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var href = decodeURI(location.search);
     var r = href.substr(1).match(reg);
    // r = decodeURI(r);
     if(r!=null)return unescape(r[2]); return null;
}




window.onload=function(){
//接收单个参数
var Ohref=window.location.href;
var arrhref=Ohref.split("?id=");
alert(arrhref[1]);
var typeName = arrhref[1];
console.log(typeName);

//打印接收到的多个参数
var name = GetQueryString("names");
var exp = GetQueryString("exp");
var tell = GetQueryString("tell");
var orders = GetQueryString("orders");
//输出得到的结果
console.log(name+exp+tell+orders);

//下面是你需要将那几个参数传递到后台 进行业务处理 再返回结果 渲染页面
var tx = exp;
var odds = orders;
$.ajax({
url : "PassOrderDatailed.do",
type : "post",
data : {"stx":tx,"orders":odds},
dataType : 'json',
timeout : 3000,  
       cache : false, 
  beforeSend : LoadFunction, //加载执行方法      
       error : erryFunction,  //错误执行方法      
     success : succFunction //成功执行方法
});
function LoadFunction() {
console.log("加载中~!");
}
function erryFunction(){
alert("暂时没有您的物流信息");
}
function succFunction(tt) {
var data = tt;
//这个函数可以将数据进行刷新
//$("#add").empty();
$.each(data,function(index, n){
 
$("#product_message").append(
"<div class='item mui-flex' >"+
"<div class='time cell fixed'>"+data[index].AcceptTime+"</div>"+
"<div class='ico'><i class='iconfont'>&#xe8e3;</i></div>"+
"<div class='txt cell' id = 'addtwo'>"+data[index].AcceptStation+"</div>"+
"</div>"
);
 
     console.log(data[index].AcceptStation+","+data[index].AcceptTime);
    });


}

猜你喜欢

转载自blog.csdn.net/qq_37531990/article/details/78737093
今日推荐