欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js获取列表多条数据(接口)

程序员文章站 2023-02-06 22:34:45
读取数据://ajax去服务器端校验$.ajax({ type:"post", url:"http://", data:{deviceid:1}, dataType:'json', success : function(data) { var jsonText = data; var ab= eva ......
读取数据:
//ajax去服务器端校验

$.ajax({
    type:"post",
url:"http://",
data:{deviceid:1},
datatype:'json',
success : function(data) {
var jsontext = data;
var ab= eval("("+jsontext+")");//json格式转换
for(j=0;j<ab.length;j++){
$(ab[j]).each(
function (i, values) {
$("#list").append(
"<tr class='ch_no'><td>" + i+1 + "</td>" +
"<td style=\"padding-left: 5%;\">" + values.isreign + "</td>" +
"<td style=\"padding-left: 5%;\">"+ values.gain + "</td>" +
"<td style=\"padding-left: 5%;\">" +
"<select id=\"outputpower\">\n" +
" <option selected=\"selected\">"+values.outputpower+"</option>\n" +
"</select>" +
"</td>" +
"<td style=\"padding-left: 5%;\">" +
"<select id=\"forwardlinkrate\">\n" +
" <option selected=\"selected\">"+values.forwardlinkrate+"</option>\n" +
"</select>"+
"<td style=\"padding-left: 5%;\">" +
"<select id=\"reverselinkrate\">\n" +
" <option selected=\"selected\">"+values.reverselinkrate+"</option>\n" +
"</select>" +
"</td>" +
"<td style=\"padding-left: 5%;\">" +
"<select id=\"forwardmodtype\">\n" +
" <option selected=\"selected\">"+values.forwardmodtype+"</option>\n" +
"</select>" +
"</td>" +
"<td style=\"padding-left: 5%;\">" +
"<select id=\"reversemodtype\">\n" +
" <option selected=\"selected\">"+values.reversemodtype+"</option>\n" +
"</select>" +
"</td>" +
"<td style=\"padding-left: 5%;\">" +
"<select id=\"outputrate\">\n" +
" <option selected=\"selected\">"+values.outputrate+"</option>\n" +
" <option>不限</option>" +
"</select>" +
"</td></tr>"
);
}
);
}
}
});

保存数据:
$("#btnsubmit").on('click',(function () {
var ab = new array();
var ch_no = $('.ch_no');
var adiv=document.getelementsbyclassname("ch_no");//获取文档中class为"ch_no"的所有元素
    for (var i = 0;i<adiv.length;i++) {//遍历 adiv的中所有元素并且将所有class为"ch_no"的元素保存到数组aerial
        var outputpower_con = $(ch_no[i]).find("#outputpower").find("option:selected").val();
var forwardlinkrate_con = $(ch_no[i]).find("#forwardlinkrate").find("option:selected").val();
var reverselinkrate_con = $(ch_no[i]).find("#reverselinkrate").find("option:selected").val();
var forwardmodtype_con = $(ch_no[i]).find("#forwardmodtype").find("option:selected").val();
var reversemodtype_con = $(ch_no[i]).find("#reversemodtype").find("option:selected").val();
var outputrate_con = $(ch_no[i]).find("#outputrate").find("option:selected").val();
aerial.push({
outputpower: outputpower_con,
forwardlinkrate: forwardlinkrate_con,
reverselinkrate: reverselinkrate_con,
forwardmodtype: forwardmodtype_con,
reversemodtype: reversemodtype_con,
outputrate: outputrate_con
})
}
console.log(ab);
$.ajax({
url: "http://",//接口地址
type:'post',
data: ab,
datatype: 'json',
success : function(data) {
console.log(data)
},
error : function() {
alert('保存失败,请重试! ');
}
})
})