ajax傳值到後台,這樣寫直接輸出data error;
data: "{'s':'" + selectedText + "'}",沒辦法傳帶單引號的
data: "{ \"s\":\""+ selectedText+"\" }",沒辦法傳帶雙引號的
function ajaxSend() {
jQuery.blockUI({ message: "處理中,請稍候...<img src='閱讀_files/content/images/加載-007.gif' />", css: { color: 'black', border: '3px solid #aaa', backgroundColor: 'white' }, overlayCSS: { opacity: '0.0' } });
alert("解析過程需要10秒,如有卡頓,請稍等");
$.ajax({
type: "Post",
url: "Reader.aspx/GetStr",
async: false,
//data: "{'s':'" + selectedText + "'}",
data: { s: selectedText },
//data: "{ \"s\":\""+ selectedText+"\" }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
$('#Report').html(data.d);
jQuery.unblockUI();
$('html,body').animate({ scrollTop: document.body.clientHeight + 'px' });//跳轉至頁面最底部
},
error: function (err) {
alert("data error");
jQuery.unblockUI();
}
});
}
你的selectedText包含單引號或者雙引號?替換轉義下,要不字符串不閉合了
data:'{"s":"' + selectedText.replace(/"/g,'\\"') + '"}',