標籤:
//一般處理常式,GET方式提交(data:要傳送的資料索引值對)
jQuery.ajax(
{ type: ‘GET‘,
url: ‘GradeHandler.ashx?startCount&starDescri‘,
data: { startCount: startCount, starDescri: starDescri }, //(對)
// data: ‘{ startCount:"‘ + startCount + ‘",starDescri:"‘ + starDescri + ‘"}‘, (錯)
contentType: "application/json; charset=utf-8",
dataType: ‘json‘,
success: function (result) {
if (result)//返回true
alert(‘評分成功!‘);
else
alert(‘評分失敗‘ + result);
},
error: function () {
alert("ajax調用錯誤");
}
}
);
//一般處理常式,POST方式提交(data:要傳送的資料索引值對)
jQuery.ajax(
{ type: ‘POST‘,
url: ‘GradeHandler.ashx‘,
data: { startCount: startCount, starDescri: starDescri }, //(對)
// data: ‘{ startCount:"‘ + startCount + ‘",starDescri:"‘ + starDescri + ‘"}‘, //(錯)
// contentType: "application/json; charset=utf-8", //不能添加該參數
dataType: ‘json‘,
success: function (result) {
if (result)//返回true
alert(‘評分成功!‘);
else
alert(‘評分失敗‘ + result);
},
error: function () {
alert("ajax調用錯誤");
}
}
);
/*
jQuery調用WebService的方法(只能發送post方式的請求);
返回json格式的資料時,需設定contentType為application/json (data要用Json的字串格式傳入)
返回的資料是以字母d為索引值的json對象。
*/
jQuery.ajax(
{ type: ‘POST‘,
url: ‘WebService/GradeWebService.asmx/UserGrade‘,
data: ‘{ count:"‘ + startCount + ‘",descri:"‘ + starDescri + ‘"}‘, //(對)
// data: { count: startCount, descri: starDescri }, //(錯)
contentType: "application/json; charset=utf-8",
dataType: ‘json‘,
success: function (result) {
if (result.d)//返回true
alert(‘評分成功!‘ + result.d);
else
alert(‘評分失敗‘ + result.d);
},
error: function () {
alert("ajax調用錯誤");
}
}
);
.net jquery ajax應用(前端)