jQuery的ajax調用很方便,傳參的時候喜歡用Json的數據格式。比如:
復制代碼 代碼如下:
function AddComment(content) {
var threadId = $("#span_thread_id").html();
var groupId = $("#span_group_id").html();
var groupType = $("#span_group_type").html();
var + threadId + ',groupId:' + groupId + ',groupType:' + groupType + ',title:"' + title + '",content:"' + content + '"}', type: 'post',
dataType: 'json',
contentType: 'application/json;charset=utf-8',
cache: false,
success: function(data) {
//根據返回值data.d判斷是不是成功
},
error: function(xhr) {
//中間發生異常,查看xhr.responseText
}
});
}
復制代碼 代碼如下:
function AddComment(content) {
var comment = {};
comment.threadId = $("#span_thread_id").html();
comment.groupId = $("#span_group_id").html();
comment.groupType = $("#span_group_type").html();
comment.title = $("#thread_title").html();
comment.content = content;
$.ajax({
url: '/WebService/GroupService.asmx/AddThreadComment',
data: $.toJSON(comment),
type: 'post',
dataType: 'json',
contentType: 'application/json;charset=utf-8',
cache: false,
success: function(data) {
//根據返回值data.d處理
},
error: function(xhr) {
//中間發生異常,具體查看xhr.responseText
}
});
}
新聞熱點
疑難解答
圖片精選