Note that there are some explanatory texts on larger screens.

plurals
  1. PORedirecting a HTML form to an Ajax request
    primarykey
    data
    text
    <p>I'm testing out some code at the moment and basically attempting to redirect a HTML form to an AJAX call (POST) which displays the response of a script running on my server.</p> <p><strong>HTML</strong></p> <pre><code>&lt;form id='form' name='qform' method='post' action='./resources/comment-redirect.php'&gt; &lt;input type='search' name='name' class='comment-instance' autofocus='autofocus' value='name' /&gt; &lt;input type='search' name='email' class='comment-instance' autofocus='autofocus' value='email (not published)' /&gt; &lt;TEXTAREA name='comment-box' class='comment-instance' COLS=60 ROWS=5 value='email' /&gt; &lt;button type='submit' id='comment-submit' value='Submit'&gt;--SUBMIT--&lt;/button&gt; &lt;/form&gt; </code></pre> <p><strong>JAVASCRIPT</strong> </p> <pre><code>$('#comment-submit').click(function(e){ e.preventDefault(); console.log("User clicked"); jQuery.ajax({ type:'POST', url: './resources/comment-redirect.php', data: {'name':$('[name=name]').val().toString(), 'email':$('[name=email]').val().toString(), 'comment':$('[name=comment-box]').val().toString() }, dataType: 'json', success: function(result){ console.log(result); } }); //end of JQuery.Ajax() //PHP if( !empty($_GET['a'] ) ) { print("This request has been routed to GET\n"); } else if( !empty($_POST) ) { print("This request has been routed to POST\n"); print($_POST); } else { print("Other"); } </code></pre> <p>So at the moment, in the console window I get 'User clicked', meaning that the callback does work - however there is no AJAX response. I've used a browser and manually tested my PHP script and that passes as well (both GET and POST). So for some reason this Ajax call doesn't seem to be firing.</p> <p>Any help would be greatly appreciated Stack.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload