BlondePainter BlondePainter - 1 year ago 62
Ajax Question

PHP page not recieving POSTed jquery ajax request

I have my first PHP page having search form:

<form action="#" class="form-inline" id="form_srch">
<input type="text" id="toSearch" name="toSearch" placeholder="Enter Application Number" class="form-control" style="width:250px" required >
<button type="button" class="btn btn-primary" onclick="search()">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
<i><b><p style="display:none;color:red" id="result">** Empty Value</p></b></i>

<div id="ajax"></div>

and a javascript function

function liveCheck() {

function search() {
var inp = $("#toSearch").val();
if(jQuery.trim(inp).length > 0)
url: "load_search_prereg.php",
data:{ to : inp },
type: "POST",
error:function (){}


And i have my second PHP page named
to process the POSTed input and the code is

require '../backend/_classes.php';
$x = new DB();
$id = $_POST['to'];
$fetch = $sql->fetchObject();

The problem is when i clicked the search button in my first PHP page, It displays no array of posted data while im using the
method in my javascript. But when i use
, it returns the expected result. Does the problem occur in
method ? Help pls.

Answer Source





I've assumed you just want to write this data into div

edit: instead of var_dump($fetch); you must return your data a JSON object, eg:

$fetch = $sql->fetchObject();
echo json_encode($fetch);

Then you can do in js what you want

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download