Note that there are some explanatory texts on larger screens.

plurals
  1. POAjax query not sending request to server
    primarykey
    data
    text
    <p>I'm working on adding some Ajax to a web page that I have using jQuery. Note that I'm new to Ajax. The page is a simple registration form, and I want to check if the email address the user supplies is already registered, and tell the user if it is, before the form redirects to registration code.</p> <p>I've been reading <a href="https://stackoverflow.com/questions/10362430/ajax-call-to-check-duplicate-data">this question</a> and its answers, and experimenting to reproduce the effect, but without success.</p> <p>When I click on submit, the javascript function is called (I've proven this by adding some diagnostic code into the <code>checkEmail()</code> function), however when I check my Apache server logs, I can see all the requests that I'm expecting, except for the call to <code>/user/process/chechemail.php</code>. The code (below) is located in the <code>/user/</code> directory, I've modified the <code>url:</code> path with all variations of relative and absolute paths. Nothing is recorded in the Apache error log.</p> <p>When the user clicks the submit button, they see the message "Something went wrong!". Can anyone spot what is wrong?</p> <p>The code I have is as follows:</p> <pre><code>&lt;script&gt; function checkEmail() { $.ajax( { type: "POST", dataType: "html", data: { email: $('#email').val() }, url: "/user/process/checkemail.php" }) .done(function(response) { $('#message').html(response); }) .fail(function() { $('#message').html("Something went wrong!"); return false; }); } &lt;/script&gt; &lt;div id="register-form"&gt; &lt;form name="register" action="process/register.php" method="post" onsubmit="return checkEmail();"&gt; &lt;div class="register-email-cell"&gt; &lt;p class="text"&gt;Email Address&lt;/p&gt; &lt;/div&gt; &lt;div class="register-email-cell"&gt; &lt;input class="input" type="text" name="email"&gt; &lt;/div&gt; &lt;div class="register-email-cell"&gt; &lt;input class="button" type="submit" value="Register"&gt; &lt;/div&gt; &lt;div&gt; &lt;p id="message" class="text"&gt;&lt;/p&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; </code></pre> <p>Notes:</p> <ul> <li>The <code>&lt;script&gt;</code> reference to jQuery is in a PHP include, not shown above</li> <li>/user/process/checkemail.php - looks for $_REQUEST['email'], and performs a query against the database and returns a string stating either 'Email address exists' or 'Email address available' - I realise that this might allow bots to harvest email addresses, but this is just sample code used for my own learning. - It isn't going to be production code.</li> </ul>
    singulars
    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.
    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