This is a jquery/ajax problem. The jquery/ajax is responding to keyup event with the alert(loc) showing the result of the value inputted into the number textbox.
The essense of the program is to get data from the database which is in an array form after encoding with json via php and display the result inside the textbox.
However, reaching the .ajax function, it does not display anything inside the success section. At the end, there is no response or any error. Used JSONLINT to see if there is any error, it gave a code i dont understand.
Afte using mozilla firebug to step through jquery, it still did not show any message.
This are my html,php,jquery codes for verification.
JS:
$(document).ready(function() {
$('#number').keyup(function() { //keyup event responds
var loc = $('#number').val();
alert(loc); //display result from the number textbox
$.ajax({ //skips ajax function
dataType: "json"
url: "/php/barry.php",
data: ({loc : loc}),
async: false,
type: "GET",
contentType: "application/json; charset=utf-8
success: function(data) {
$.each(data.result, function()
{
$("#number").append(this['number']);// its suppose to display
$("#name").append(this['name']);
});
}
});
});
});
PHP:
<?php
include_once('/db.php');
if(isset($_GET['loc'])){
$foo = $_GET['loc'];
$sql = "SELECT * FROM freak where number='$foo'";
$res = mysql_query($sql);
$result = array();
while( $row = mysql_fetch_array($res) )
array_push($result, array('number' => $row[0],
'name'=> $row[1];
//print_r($result);
echo json_encode(array("result" => $result));
}
?>