ajax, jquery, and php form load issues

Discussion in 'Web Design and Development' started by hansolo669, Apr 5, 2012.

  1. hansolo669, Apr 5, 2012
    Last edited: Apr 5, 2012

    hansolo669 macrumors regular

    Oct 5, 2009
    I have searched long and hard to find a solution to this problem to no avail.

    here is the jquery. on the php side I'm just using a small string to detect headers and such.

    <script type="text/javascript" src="jquery.js"></script> 
    <script type="text/javascript">
    $("body").on("click", "button", function(){
      type: 'POST',
      url: 'exec.php',
      cache: false,
        //loading image
        $('#out').html('<div class="loading"><img src="loader.gif" alt="Loading..." /></div>');
        //output the data
        $('#out').html('<p class="error"><strong>Oops!</strong> Try again...</p>');
    <div class="form">
    <button>Play the Game</button>
    (i know, i know "you should use $.post instead" I'm useing $.ajax beacuse it gives me a bit clearer idea of what is happening)

    the issue I'm having is that while the ajax appears to activate every time, the php only responds the second time.

    I.E. click(ajax send. no response), click(ajax send. response), click(ajax send. no response), click(ajax send. response) etc.

    any help would be appreciated
  2. jared_kipe macrumors 68030


    Dec 8, 2003
    Example page?

    Out of curiosity, why not do something like jQuery('button').click( function); ?
  3. hansolo669 thread starter macrumors regular

    Oct 5, 2009
    i actually did move to the ('button').click(fucntion); style method after i posted this.

    as for example page... that should give you an idea on what im trying to do here.
  4. Eclipse278, Apr 7, 2012
    Last edited: Apr 7, 2012

    Eclipse278 macrumors regular

    Jan 21, 2007
    Ugh. I'm not the best at jQuery or javascript, but I don't think you want to have this in the "document ready" part.

    move the < script > and < style > parts into < head > first.

    then replace
    $(document).ready(function() {
    $("body").on("click", "button", function(){
    with function loadajax(){

    erase a }); since you've erased the .ready parenthesis
    change the last }); to } since you're not inside an .on( anymore

    then change <button>Play the Game</button> to <button onclick="loadajax();">Play the Game</button>
  5. jared_kipe macrumors 68030


    Dec 8, 2003
    No, adding event handlers after the document is ready is a common and modern approach. It lets you cleanly separate your scripts out of your HTML markup (by not having inline onclick="JS" events).


    There are a plethora of errors generated on each press.

    Refreshing the page itself (http://roulette.ccegameplay.com/dev/index_beta2.php) causes intermittent timeouts. So replying on a timely ajax call maybe a server problem.

    Refreshing the page you are ajax getting has the same problem (http://roulette.ccegameplay.com/dev/exec.php) intermittent time out and lots of errors in console.
  6. hansolo669 thread starter macrumors regular

    Oct 5, 2009
    the php script I'm running is very simple(create random 5 char string, append that to imgur.com/ get headers, and return the whole thing back).

    I had a feeling it would be server related.
    for knowledge's sake I'm running the server on a powermac g4 1ghz (the MDD fw800 version)2gb of ram, and i have a 80gb hdd dedicated to web serving. I'm useing osx server 10.4 with all the latest and greatest updates.
    I hacked in support for php5 and a newer version of mysql.

    thanks to everyone who helped it is very much appreciated, and it looks like a newer/more powerful linux based personal server is in my future. :p

Share This Page