Retrieve plain text with jquery ajax and convert to JSON -


update: following works fine in ie8, data comes null in firefox:

$.getjson('myurl/solr/select/?q=citystate%3asea*&version=2.2&start=0&rows=3&indent=on&wt=json&fl=citystate', function(data) {   alert(data.response.docs[0].citystate); }); 

i have jetty server generates json data plain text - here headers like:

last-modified   wed, 06 oct 2010 23:22:27 gmt etag    "oti5ywmzyzfkndgwmdawmfnvbhi=" content-type    text/plain; charset=utf-8 content-length  565 server  jetty(6.1.3) 

here example of output:

{  "responseheader":{   "status":0,   "qtime":1,   "params":{     "fl":"citystate",     "indent":"on",     "start":"0",     "q":"citystate:sea*",     "wt":"json",     "version":"2.2",     "rows":"10"}},  "response":{"numfound":233,"start":0,"docs":[     {      "citystate":"seaboard, al"},     {      "citystate":"seale, al"},     {      "citystate":"seacliff, al"},     {      "citystate":"sealy springs, al"},     {      "citystate":"searcy, al"},     {      "citystate":"searight, al"},     {      "citystate":"searles, al"},     {      "citystate":"seasha, al"},     {      "citystate":"searcy, ar"},     {      "citystate":"seaton, ar"}]  }} 

i want retrieve data using jquery ajax call this:

$.ajax({   type: "get",   url: "myurl/?q=citystate%3asea*&version=2.2&start=0&rows=10&indent=on&wt=json&fl=citystate",   datatype: "json",   contenttype: "text/plain; charset=utf-8",   success: function(data, textstatus){     alert("data: " + data);   },   error: function(data){     alert("error");   } }); 

however, result null. doing wrong?

if can't server send proper content-type header (ie. application/json or text/javascript) should expect plain text datatype: 'text' , evaluate it.

function(data){     eval('var data = ' + data + ';');     // rest of code } 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -

PostgreSQL 9.x - pg_read_binary_file & inserting files into bytea -