In MVC, if not an HTML returned from the controller, but a text, how to get it using AJAX?
Public ActionResult Uploadpicture ()
{
Return Content ("OK");
Return Content ("{result: '" + imgmsg + "', url: '" + Imgurl + "'}"); We are returning characters in JSON format
}
Ajax Code:
$.ajax ({
Type: "POST",
URL: "/classbasic/uploadpicture",
Data:null,
DataType: "Text",
Success:function (d) {
alert (d);
}
});
More than just returning to view () The Ajax of a datatype, which means the type of return
Expected data type returned by the server. If not specified, JQuery is automatically judged intelligently based on the HTTP packet mime information, such as the XML MIME type being recognized as XML. In 1.4, JSON generates a JavaScript object, and script executes it. The data returned by the server is then parsed against this value and passed to the callback function. Available values:
"XML": Returns an XML document that can be processed with jQuery.
HTML: Returns plain text HTML information, and the included script tag is executed when the DOM is inserted.
"Script": Returns plain text JavaScript code. Results are not automatically cached. Unless the "cache" parameter is set. "Note:" On a remote request (not in the same domain), all post requests are converted to get requests. (because the script tag of the DOM will be used to load)
"JSON": Returns the JSON data.
"JSONP": Jsonp format. When calling a function using JSONP form, such as "myurl?callback=?" JQuery is automatically replaced? is the correct function name to execute the callback function.
"Text": Returns a plain text string
Ajax return Data type