javascript - Ajax MVC Partial Returning Correct Response Yet Fires the Error Handler -


this has me stumped. odd.

i have ajax function defined:

$.ajax({     type: 'get',     datatype: 'text/html',     url: getlicenseedetailsurl,     success: function (response) {         $('#licenseedetails').html('');         $('#licenseedetails').html(response);     },     error: function (xhr) {         alert('failed licensee details');     } }); 

and have calling controller has action like:

public actionresult loadlicenseedetails(long licenseeid) {     var model = new licenseedetailsviewmodel();      var licencesee = _licensingrepository.loadbyid(licenseeid);     var licenses = _licensingrepository.loadlicenses(licenseeid);      model.licencee = mapper.map<licensee, licenceeviewmodel>(licencesee);     model.licences = mapper.map<ienumerable<license>, ienumerable<licenceviewmodel>>(licenses);      return this.partialview("_licenseedetails", model); } 

this seems working expected without errors, ends firing ajax error function, not success function.

looking @ xhr.responsetext can see correct response information action controller!!

all status 200 ok well. on earth doing wrong here?

what on earth doing wrong here?

this:

datatype: 'text/html' 

should become:

datatype: 'html' 

quote documentation of datatype parameter:

datatype (default: intelligent guess (xml, json, script, or html))

type: string

the type of data you're expecting server. if none specified, jquery try infer based on mime type of response (an xml mime type yield xml, in 1.4 json yield javascript object, in 1.4 script execute script, , else returned string). available types (and result passed first argument success callback) are:

"xml": returns xml document can processed via jquery.

"html": returns html plain text; included script tags evaluated when inserted in dom.

"script": evaluates response javascript , returns plain text. disables caching appending query string parameter, "_=[timestamp]", url unless cache option set true. note: turn posts gets remote-domain requests.

"json": evaluates response json , returns javascript object. json data parsed in strict manner; malformed json rejected , parse error thrown. of jquery 1.9, empty response rejected; server should return response of null or {} instead. (see json.org more information on proper json formatting.)

"jsonp": loads in json block using jsonp. adds "?callback=?" end of url specify callback. disables caching appending query string parameter, "_=[timestamp]", url unless cache option set true.

"text": plain text string.

multiple, space-separated values: of jquery 1.5, jquery can convert datatype received in content-type header require. example, if want text response treated xml, use "text xml" datatype. can make jsonp request, have received text, , interpreted jquery xml: "jsonp text xml." similarly, shorthand string such "jsonp xml" first attempt convert jsonp xml, and, failing that, convert jsonp text, , text xml.

or better, rid of parameter. jquery intelligent enough use content-type response http header set server in order deduce correct type , process parameter passed success callback.

look @ console tab of javascript debugging toolbar in browser. provide more information error.


Comments

Popular posts from this blog

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -