我作出這樣一個JSON調用一個ASHX處理程序:返回JSON來的JavaScript
attributes = $("#pageHtmlTag").attr("class").trim();
urlToHandler = 'JSonTestHandler.ashx';
jsonData = '{' + attributes + '}';
$.ajax({
url: urlToHandler,
data: jsonData,
dataType: 'json',
type: 'POST',
contentType: 'application/json',
success: function (data) {
setAutocompleteData(data.responseDateTime);
$("body").add("<div>" + data.toString() + " </div>").appendTo(document.body);
alert("grate suceees");
},
error: function (data, status, jqXHR) {
alert('There was an error.' + jqXHR);
}
}); // end $.ajax
我receieve它和proccess它。我也想發回一些HTML來顯示,但我不知道如何發送回到Jscript的HTML。
ASHX:
string jsonData = new StreamReader(context.Request.InputStream, System.Text.Encoding.UTF8).ReadToEnd();
.............................
var testResultReportString = testResultReport.GetReportHtml();
var serializer = new JavaScriptSerializer();
var jSonTestResultReport = serializer.Serialize(testResultReportString);
context.Response.Write(jSonTestResultReport);
所以,問題是。我如何將數據返回到Ajax調用成功函數?
它不工作。我在警報彈出窗口中收到錯誤: 語法錯誤。意外的令牌= 我發回的輸出是: {「resultReport」=「
哦,我想通了。我使用了an =而不是: – Lautaro