有效Ajax案例
阅读原文时间:2023年07月08日阅读:3



function commit(){
$.ajax({
type: 'GET',
// dataType: 'json',
async: true,
url: "editArticleSubmit1",
data: {
name:$("#name").val(),
sex:$("#sex").val(),
age:$("#age").val(),
purpose:$("#purpose").val(),
workAge:$("#workAge").val(),
content:$("#content").val(),
},
success: function (data) {
// obj=eval('('+obj+')');//这段代码就是将字符串转换成json格式

        /\*var name = this.data.name;  
        var sex = this.data.sex;  
        var age = this.data.age;  
        var purpose = this.data.purpose;  
        var workAge = this.data.workAge;  
        var content = this.data.content;\*/

        alert("投递成功");  
    }, error: function (msg,status) {  
        alert(msg+status);  
        return;  
    }  
});  
// var a=$("#massage").val();  
// alert(a)  

}

ajax发送获取数据处理后显示在前端页面

function articleList(page) {
$.ajax({
url: "indeArticleList",
data: {
pageNum: page,
pageSize: 9
},
type: 'GET',
dataType: 'json',
async: true,
success: function (data) {
var list = data.list;
$("#prePage").val(data.prePage);
$("#nextPage").val(data.nextPage);
$("#tailPage").val(data.pages);
$("#pageNum").text(data.pageNum);
console.log(list);
if(list != null && list.length > 0){
$("#container").empty();
var articleDiv = "";
for(var i=0; i" + "

" + " " + " " + "
" + "
" + "

"+list[i].title+"

" + "

"+list[i].summary+"

" + " "+list[i].createDate+"" + "
" + " " + "
" +
"
";
if(i>0 && i%3==0){
articleDiv += "
" + article;
}else{
articleDiv += article;
}
}
articleDiv += "
";
$("#container").append(articleDiv);
}
},
error: function (msg) {
alert("服务器异常,请稍后再试!")
return;
}
});
}

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器