Getting error when try to pass data from a php file back to JSON javascript -
Getting error when try to pass data from a php file back to JSON javascript -
let's me describe i'm working on before inquire question:
i'm building clinic queuing management system, in part of system, have 3 files here, index.php, test.php , test.js respectively.
==> test.js send request test.php 2 json data, there $queuenumber , $room stored in test.php. after append new in index.php , under append 2 shows $queuenumber , $room.
==> test.php produce ticket number , room number stored in $queuenumber , $room respectively.
==> index.php file contain 2 table, 1 table header , 1 table show ticket number , room number.
the next code of index.php
class="snippet-code-html lang-html prettyprint-override"><!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>and san king emr</title> </head> <body> <table width="95%" align="center" border="1"> <tr> <th width="50%" style="font-size:40px;">number</th> <th width="50%" style="font-size:40px;">office</th> </tr> </table> <table width="95%" align="center" border="1" id="queuedisplay"> </table> <script src="/system/javascript/jquery.js"></script> <script src="test.js"></script> </body> </html>
the next code of test.js
class="snippet-code-js lang-js prettyprint-override">$(document).ready(function(){ $.ajax({ url: "test.php", data:""; datatype: "json", success : function (data) { x=data.queuenumber; y=data.room; alert('the queue number '+ x +' , room '+ y); }, }); });
the next code of test.php
class="snippet-code-html lang-html prettyprint-override"><?php include("connect.php"); $sql = mysql_query("select * queue status='calling' order id asc limit 1"); $row = mysql_fetch_array($sql); $queuenumber = $row['queuenumber']; $room = $row['room']; $json = array("$queuenumber","$room"); echo json_encode($json); ?>
question: when seek run index.php, next error message, should solve error message?
error syntax error: json.parse: unexpected character @ line 1 column 1 of json data
the file process.php should include php code , info should return. omit other html tags. process.php this:
<?php include("connect.php"); $sql = mysql_query("select * queue status='calling' order id asc limit 1"); $row = mysql_fetch_array($sql); $id = $row['id']; $queuenumber = $row['queuenumber']; $room = $row['room']; $run = mysql_query("update queue set status='called' id='$id'"); $json = array("$queuenumber","$room"); echo json_encode($json); ?>
php json
Comments
Post a Comment