0

Let's me describe what I'm working on before I ask my question:

I'm building a clinic queuing management system, in part of the system, I have three files here, they are index.php, test.php and test.js respectively.

==> test.js will send request to test.php to get 2 JSON data, there are $queueNumber and $room stored in test.php. After that will append a new in index.php and under that will append 2 which shows $queueNumber and $room.

==> test.php produce a ticket number and a room number stored in $queueNumber and $room respectively.

==> index.php is just a file that contain 2 table, 1 table for header and 1 table to show the ticket number and room number.

The following is code of index.php

<!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 following is the code of test.js

$(document).ready(function(){

	$.ajax({
    url: "test.php",
    data:"";
    dataType: "json",
    success : function (data) {
        x=data.queueNumber;
        y=data.room;
        alert('The queue number is '+ x +' and the room is '+ y);
    },
});
});

the following is code of test.php

<?php
    include("connect.php");
    $sql = mysql_query("SELECT * FROM queue WHERE status='calling' ORDER BY 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 I try to run index.php, I get the following error message, I should I solve this error message?

error syntax error: JSON.parse: unexpected character at line 1 column 1 of the JSON data

1 Answer 1

1

The file process.php should only include php code and data that should return. omit other html tags. So process.php would be only this:

<?php
    include("connect.php");
    $sql = mysql_query("SELECT * FROM queue WHERE status='calling' ORDER BY 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' WHERE ID='$ID'");
    $json = array("$queueNumber","$room");
    echo json_encode($json);
?>
Sign up to request clarification or add additional context in comments.

4 Comments

if I'm not going to send data from display.php to process.php, can I delete the line (data:"";) in that process.js?
from that process.php, I can get the result like this if I run that page directly in browser ==> ["A001","1"] But, I cannot get any response from that display.html, I didn't get any javascript alert like I programmed in that process.js, where do you think could possibly goes wrong?
In ajax block, after data="" there should be comma not semicolon also in line 10 of js , there should not be comma after closing }
Also make sure that connect.php is empty from html tags and extra data

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.