John Jones
John Jones

Reputation: 2275

jquery post to php call back problem

having murders with this jQuery.

I am trying to show a set of db results when the user clicks on a div layer, seems to access the function but will not return the results of the PHP file into the div results. Any thoughts?

<script type="text/javascript">
  $(document).ready(function() {
    $('#clickme').click(function() {
      //alert('clicked');
      $.get("doquery.php", {id: 1, action: all}, function(result) {
        $("#results").html(result);
      });
    });
  });
</script>

<div id="clickme">
Show results
</div>

<div id="results"></div>

Upvotes: 0

Views: 1113

Answers (4)

John Jones
John Jones

Reputation: 2275

Cheers for the response I sorted the problem. It was this line of code:

$.get("doquery.php", {id: 1, action: all}, function(result) {

The action: all should have been in hyphens action:'all'

Silly mistake, had a clean look this monring and straight away I notice the problem.

Thanks once again.

Upvotes: 0

googletorp
googletorp

Reputation: 33295

With firebug it is possible to see the request and response of the get request. So I would start there and see what gets returned instead of alerting. If the response is good look at the callback function. It do sound like the problem is in the php script. You could also try returning some simple static data out flat and see what that gets you.

Upvotes: 0

Matthew Groves
Matthew Groves

Reputation: 26169

Are you sure "doquery.php" is the correct path? You may be getting a 404 because it should actually be /scripts/doquery.php or something like that.

Upvotes: 0

Tomalak
Tomalak

Reputation: 338416

My suspicion is that the PHP page does return an error of some sorts. The callback of $.get() is only executed on success ("200 OK").

To have callbacks executed on all kinds of HTTP response status values, look into $.ajax().

Upvotes: 1

Related Questions