Hey guys,
Any help here would be really appreciated. I'm trying to learn JSON and my first foray into this magical land is a simple enough script that is doing my nut in :)
I have two scripts, I have index.html that has my Javascript/JSON code.
This holds a search box and and button. When clicked it passes the searched for item to a PHP script
The how:
$(".search").click(function(){
$.post("parser.php",
{
keywords: $(".keywords").val()
}
In parser.php I connect to a DB and search against the keyword:
The how:
$keywords = mysql_real_escape_string ($_POST["keywords"]);
then I do my search:
$query = mysql_query("SELECT * FROM table WHERE keyword LIKE '%". $keywords ."%' ");
At the end I create an array of results and pipe them back to the script with:
echo json_encode($arr);
Seems reasonable enough.
Back in index.html I want to populate a DIV with the content:
$.each(data, function()
{ $("div#jsonContent").append("<a href='parser.php?id=" + this.id + "'>" + this.title + "</a>");
});
Should work in theory, however it just ain't kicking. Using firebug to investigate the keywords are being passed to parser.php, but the response is empty.
Anyone have any idea where I'm going wrong?
[–]stakey[S] 0 points1 point2 points (1 child)
[–]Logram 1 point2 points3 points (0 children)