title: Jquery Mobile - Ajax call to fetch data from MySql database returning error
body: <p>Jquery Mobile - Ajax call to fetch data from Json data from MySql database returning error.</p>
  
  <p>Here's my code</p>
  
  <p>Server code</p>
  
  <pre><code>&lt;?php
  
  try{
  
  header('Content-type: application/json');
  
  $server = "myurl";
  $username = "username";
  $password = "password";
  $database = "mydb";
  $con = mysqli_connect($server, $username, $password, $database) or die       ("Could not connect: " . mysql_error());
  /*mysql_select_db($database, $con);
  
  $result = mysql_query($sql) or die ("Query error: " . mysql_error());
  $records = array();
  */
  $sql = "SELECT id, l_name AS name, l_lat AS value1, l_long AS value2 FROM     landmarks ORDER BY l_name";
  $result= mysqli_query($con, $sql);
  $records = array();
  
  while($row = mysqli_fetch_assoc($result)) {
  $records[] = $row;
  }
  mysqli_close($con);
  echo json_encode($records); 
  
  
  
  } 
  catch(Throwable $e) {
  $trace = $e-&gt;getTrace();
  echo $e-&gt;getMessage().' in '.$e-&gt;getFile().' on line '.$e-&gt;getLine().' called from '.$trace[0]['file'].' on line '.$trace[0]['line'];
  }
  
  
  
  
  
  ?&gt;
  </code></pre>
  
  <p>my ajax call</p>
  
  <pre><code>try {
      $.ajax({
          url: 'myurl',
          dataType: 'jsonp',
          jsonp: 'jsoncallback',
          timeout: 5000,
          success: function(data, status){
              $.each(data, function(i,item){ 
                  var res = '&lt;h1&gt;'+item.name+'&lt;/h1&gt;'
                  + '&lt;p&gt;'+item.value1+'&lt;br&gt;'
                  + item.value2+'&lt;/p&gt;';
  
                  output.append(res);
              });
          },
          error: function(){
             output.text('There was an error loading the data.');
          }
      });
  
  }
  catch (e) {
  
     logMyErrors(e); 
  }
  </code></pre>
  
  <p>Here ajax is returning the error function.</p>
  
  <p>But while running the server code in the browser, json data is displayed correctly. 
  <a href="https://i.stack.imgur.com/udgbP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/udgbP.jpg" alt="enter image description here"></a></p>
  
  <p>Nothing is being logged in the console. Please help to find out what has gone wrong.</p>