tags:

views:

360

answers:

4

Hi there, 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>
+1  A: 

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().

Tomalak
Still dont have any ideas, the doquery.php page is in the same path as the html and the php page on its our give a "200 OK". Very stumped.
John Jones
The fact that alert(result) is not called at all clearly indicates that the HTTP request did not result in a success. You may want to check in FireBug what actually happens, this will uncover the error quickly.
Tomalak
A: 

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.

mgroves
its the root path same as the HTMl file, I have live HTTP headers on firefox and no output when I click the text, so it seems to be failing to call the php.
John Jones
A: 

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.

googletorp
A: 

Hi people,

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.

John Jones