asp.net mvc - MVC JSON method returning invalid JSON to JQuery? -


i having problems jquery parsing json sending back... however, odd because using mvc's json method.

here's setup. have simple function:

$.ajax({     url: urld,     datatype: 'json',     data: { year: $('#vehicleyear').val(), value: request.term },     success: function (data, textstatus, jqxhr) { alert("success!"); },     error: function(xmlhttprequest, textstatus) {           alert(textstatus + ": " + xmlhttprequest.responsetext);       }   }); 

it runs error function shows:

parsererror: [{"value":"toyota","id":160}]

i cannot figure out why in world doing this... it working older version of jquery - , read jquery json parser quite bit more strict now- can't figure out what's wrong json.

even if wrong, that's frustrating because i'm using mvc's json function generate this:

public actionresult getvehiclemodels(int year, int makeid, string value = null) {     var modlmatchs = (from vmyx in ent.vehiclemakeyearxrefs                         join vm in ent.vehiclemodels                         on vmyx.vehiclemodelid equals vm.vehiclemodelid                         join vma in ent.vehiclemakes                         on vm.vehiclemakeid equals vma.vehiclemakeid                         vmyx.modelyear == year && vma.vehiclemakeid == makeid && vm.vehiclemodelname.startswith(value)                         orderby vma.vehiclemakename                         select new { value = vm.vehiclemodelname, id = vm.vehiclemodelid }).distinct().take(10).tolist();      return this.json(modlmatchs, "application/json", jsonrequestbehavior.allowget); } 

i must missing glaringly obvious... still getting hang of jquery/mvc these things slowing progress.

sure enough, jquery result looks follows (according chrome's developer toolbar)

[{"value":"toyota","id":160}] 

change datatype in jquery ajax call "text json". suspect there may problem response content-type header, or else that's causing jquery not acknowledge datatype json. using "text json" cause jquery accept plaintext before converting js object.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -