我的ajax代码如下,它不是成功函数
function saveRecord() {
$.ajax({
url: "admin.aspx/inserData",
type: "POST",
dataType: 'text',
data: JSON.stringify({
"name": $("#name").val(),
"uName": $("#uname").val(),
"password": $("#pwd").val(),
"adminType": $("#seAdmin").val(),
"serviceArea": $("#selServiceArea").val(),
}),
contentType: "application/json; charset=utf-8",
async: false,
Success: FnInsertSuccess,
Error: FnInsertError,
});
}
和FnInsertSuccess
就在这里
function FnInsertSucces(result) {
alert(result.d);
if (result.d == "Success") {
console.log("data inserted");
// $("#tblData tbody").append("<tr style='cursor:pointer'><td>" + $("#name").val() + "</td><td>" + $("#selServiceArea").val() + "</td><td>" + $("#seAdmin").val() + "</dt><td><a class='fa fa-pencil'></a><a class='fa fa-times' onclick='FnDeleteRow(this)'></a></td></tr>");
}
else if (result.d == "Fail") {
alert("Not Successfully Insert");
}
}
答案 0 :(得分:0)
嗨使用如下成功通话。它会起作用。
$.ajax({
url:"Where u need to go",
data: //data to send
success:function(data) {
alert(data); // data will be having the stuff that gets returned from the servlet.
}
complete: //here call ur fninsert function. This will work after the ajax call is completed.
});
答案 1 :(得分:0)
function saveRecord() {
$.ajax({
url: "admin.aspx/inserData",
type: "POST",
dataType: 'text',
data: JSON.stringify({
"name": $("#name").val(),
"uName": $("#uname").val(),
"password": $("#pwd").val(),
"adminType": $("#seAdmin").val(),
"serviceArea": $("#selServiceArea").val(),
}),
contentType: "application/json; charset=utf-8",
async: false,
success: function(result){
FnInsertSuccess(result)
},
error: function(data){
FnInsertError(data);
}
});
}
答案 2 :(得分:0)
function saveRecord() {
var name = $("#name").val(),
var uName = $("#uname").val(),
var password = $("#pwd").val(),
var adminType = $("#seAdmin").val(),
var serviceArea = $("#selServiceArea").val(),
$.ajax({
url: "admin.aspx/inserData",
type: "POST",
dataType: 'JSON',
data: {
name: name,
uName: uName,
password: password,
adminType: adminType,
serviceArea: serviceArea
},
success:function(data){
FnInsertSucces(data);
}
});
}
- &GT;试试这个