Ajax Broken in Browsers works in Android -
i can run code in android app (using phonegap adn jquery mobile) not on desktop browsers. gives me syntax error in firebug line =
var ticketlist = eval("(" + ajax.responsetext + ")");  here code
// jscript source code  // ran on body load function dojsstuff() {     var ajax = ajax();     ajax.onreadystatechange = function () {         if (ajax.readystate == 4) {             var ticketlist = eval("(" + ajax.responsetext + ")");             if (ticketlist.listcount > 0) {             document.getelementbyid("opencount").innerhtml = ticketlist.listcount +" open tickets";                 (ticket in ticketlist.tickets) {                 // add stuff dom                 //addtickettolist(ticketlist.tickets[ticket]);                 }             }             else {                 document.getelementbyid("opencount").innerhtml = "all tickets reviewed";                 displaynoresults();             }         }     }     ajax.open("get", "http://website.com/listticketsrequest.ashx?pagenumber=1&pagesize=1&status=open", true);     ajax.send(null);     //document.addeventlistener("deviceready", ondeviceready, false);      //event check phonegap     //$('ul').listview('refresh');     $('#mtickets').page();     //showvars(); }  function ajax() {     var xmlhttp;     try     {         xmlhttp = new xmlhttprequest();     }     catch (e)     {     }     return xmlhttp; } **ticketlist variable in json comes across this=
{"tickets" : [{"ticketid": "1054","category": "n/a","submitteduserid": "bob.thebuilder","shortdescription": "test question qid:16668","creationdate": "2/16/2011 12:24:19 pm","ticketstatus": "open","longdescription": "something wrong question know hve right answer keeps telling me i'm wrong"},{"ticketid": "1053","category": "mission support","submitteduserid": "dave","shortdescription": "make  courseware revisions","creationdate": "2/16/2011 9:34:48 am","ticketstatus": "open","longdescription": "find tickets generated users possible courseware update."}], "pagecount": "6", "listcount": "11"} note phonegap if trying include phoengap functions in place code may executed on in browser make sure add phone gap function on "deviceready" or browser not render. example:
function onload(){         //event check phonegap         document.addeventlistener("deviceready", ondeviceready, true); } ... function ondeviceready()      {         // phonegap api ready         vibrate(90); // vib ack pg ready         $("a").click(function(event){         vibrate(30); // add 30 sec vib links         });              } 
my immediate response use jquery's getjson method, since you're aready using jquery. jquery's ajax provides broader base of browser compatibility. also, every time use eval(), small baby somewhere cries.
var url = "http://website.com/listticketsrequest.ashx?pagenumber=1&pagesize=1&status=open";  $.getjson(url ,function(ticketlist){     if (ticketlist.listcount > 0) {         $("#opencount").html(ticketlist.listcount +" open tickets");         (ticket in ticketlist.tickets) {             ...         }     } else {         $("#opencount").html("all tickets reviewed");         displaynoresults();     } }); if still doesn't work you, ensure json being returned valid. please stick method, , don't use eval!!
simplified update
var url = "http://website.com/listticketsrequest.ashx?pagenumber=1&pagesize=1&status=open"; $.getjson(url ,function(anynameyouwant){    alert(anynameyouwant.listcount + " open tickets"); }); update using 'data'
if url becomes long, might begin encounter problems. suggested pass url data via data argument.
var url = "http://website.com/listticketsrequest.ashx"; var data = "pagenumber=1&pagesize=1&status=open";  $.getjson(url, data, function(anynameyouwant){    alert(anynameyouwant.listcount + " open tickets"); }); 
Comments
Post a Comment