javascript - Cannot Parse JSON for PhoneGap App -


i've been trying parse json phonegap app dynamically generated localstorage variable. php doing it's job, javascript isn't parsing data , displaying.

my php:

header("access-control-allow-origin: *"); header('content-type: application/json; charset=utf-8');  include("conn.php");  // user id $email = $_get['email']; $useridinit="select userid users email='".$email."'"; $useridgrab=mysql_query($useridinit) or die(mysql_error()); $useridq = mysql_fetch_array($useridgrab); $userid = $useridq['userid'];  $data = array(); $q = mysql_query("select *  msg_trans left join msg_master on msg_trans.msgid=msg_master.msgid left join users on msg_master.fromid=users.userid msg_trans.toid='".$userid."' order msg_trans.status desc");  while ($row=mysql_fetch_object($q)){     $data[]=$row; } echo json_encode($data); 

my js:

var email = localstorage.getitem('email');   var url = "http://anglertrack.pixeloft.com/mobile/conn/messages.php?callback=?&email="+email;     $.getjson(url,function(result){      $.each(result, function(i, field){       var date=field.posted_date;       var from=field.fromid;       var subject=field.msgsub;       $("#messagelist").append("<li><a class='messagelink' href='message.html?date="+date+"&from="+from+"&subject="+subject+"'><span class='message'>from:"+from+"</span><h2>"+ date + " </h2><p>"+ subject +"</p></a></li>");      });      });  

my html:

<ul id="messagelist">          </ul> 

in url you're defining callback name (callback=?), unnecessary when using jquery. try using code below.

var url = "http://anglertrack.pixeloft.com/mobile/conn/messages.php?email=heath@pixeloft.com";    $.getjson(url, function(result) {    $.each(result, function(i, field) {      var date = field.posted_date;      var = field.fromid;      var subject = field.msgsub;      $("#messagelist").append("<li><a class='messagelink' href='message.html?date=" + date + "&from=" + + "&subject=" + subject + "'><span class='message'>from:" + + "</span><h2>" + date + " </h2><p>" + subject + "</p></a></li>");    });  });
<ul id="messagelist"></ul>  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -