Note that there are some explanatory texts on larger screens.

plurals
  1. PO.ajax JSONP parsererror
    text
    copied!<p>I'm trying to use an ajax call to bring back data from a web api. I wrote 2 similar functions and neither work. I can see the data come back through Fiddler, but it won't go to the success call, for both of the functions below. What am I doing wrong? The data comes back in both functions in Fiddler, it just doesn't go to success.</p> <p>Here is attempt 1:</p> <pre><code> function PopulateDivisions() { $.support.cors=true; $.ajax({ type:'GET', url:'http://IP/Service/api/DivisionSearch/GetAllDivisions', data: {}, contentType: 'application/json; charset=utf-8', dataType: 'jsonp', success: function(data) { alert(data); $("#divisionSelect").append($('&lt;option&gt;&lt;/option&gt;').val("-99").html("Select One")); $.each(data, function(i, item){ $("#divisionSelect").append($('&lt;option&gt;&lt;/option&gt;').val(item.Name).html(item.Name)); }); }, error: function(xhrequest, ErrorText, thrownError) { alert("Original: " + thrownError + " : " + ErrorText); } }); } </code></pre> <p>Error: jQuery19102671239298189216_1382022403977 was not called : parser error</p> <p>Here is the data Fiddler is showing comes back:</p> <pre><code> [{"Id":1,"Description":"Executive","Name":"Executive "},{"Id":2,"Description":"ASD","Name":"Administrative Services Division "},{"Id":3,"Description":"COM","Name":"Communications "},{"Id":4,"Description":"CP","Name":"Contracts and Procurement "},{"Id":5,"Description":"PMD","Name":"Program Management Division "},{"Id":6,"Description":"RED","Name":"Research and Evaluation Division "},{"Id":7,"Description":"IT","Name":"Information Technology "}] </code></pre> <p>Here is attempt #2:</p> <pre><code> function PopulateDivisions2() { $.support.cors=true; $.ajax({ type:'GET', url:'http://IP/Service/api/DivisionSearch/GetAllDivisionsJsonP', data: {}, contentType: 'application/json; charset=utf-8', dataType: 'jsonp', jsonp: false, jsonpCallback: "myJsonMethod", success: function(data) { //data = JSON.parse(data): alert(data); $("#divisionSelect").append($('&lt;option&gt;&lt;/option&gt;').val("-99").html("Select One")); $.each(data, function(i, item){ $("#divisionSelect").append($('&lt;option&gt;&lt;/option&gt;').val(item.Name).html(item.Name)); }); }, error: function(xhrequest, ErrorText, thrownError) { alert("PopulateDivisions2: " + thrownError + " : " + ErrorText); } }); } </code></pre> <p>Error: myJsonMethod was not called : parsererror</p> <p>Here is the data Fiddler shows is coming back:</p> <pre><code> "myJsonMethod([{\"Id\":1,\"Description\":\"Executive\",\"Name\":\"Executive \"},{\"Id\":2,\"Description\":\"ASD\",\"Name\":\"Administrative Services Division \"},{\"Id\":3,\"Description\":\"COM\",\"Name\":\"Communications \"},{\"Id\":4,\"Description\":\"CP\",\"Name\":\"Contracts and Procurement \"},{\"Id\":5,\"Description\":\"PMD\",\"Name\":\"Program Management Division \"},{\"Id\":6,\"Description\":\"RED\",\"Name\":\"Research and Evaluation Division \"},{\"Id\":7,\"Description\":\"IT\",\"Name\":\"Information Technology \"}]);" </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload