Friday, 2 June 2017
asp.net - Returning Json to javascript
Answer
I make a Json call to an ashx handler like this:
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("" + data.toString() + " ").appendTo(document.body);
alert("grate suceees");
},
error: function (data, status, jqXHR) {
alert('There was an error.' + jqXHR);
}
}); // end $.ajax
I receieve it and proccess it. I also want to send back some HTML to be displayed but i dont know how to send html back to the Jscript.
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);
So the question is. How do i return data to the Ajax calls success function?
Subscribe to:
Post Comments (Atom)
c++ - Does curly brackets matter for empty constructor?
Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...
-
A fair amount of the second act of The Dark Knight Rises has a class warfare plotline. This is foreshadowed in the trailers with Selina Ky...
-
I want to create an options array from a string. How can i create an array as { width : 100, height : 200 } from a string ...
-
I'm trying to set the size of a CardView inside of a DialogFragment , but I get this error: java.lang.NullPointerException: Attempt t...
No comments:
Post a Comment