Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To use ajax, you first need to create a server-side function that does what you need. For instance, a php script that takes a userID and returns the user's full name. Let's suppose you create that script and call it "username.php".</p> <p>On your page, you'll use a javascript function, such as the jquery <a href="http://api.jquery.com/jQuery.ajax/" rel="nofollow">.ajax</a> function to send an asynchronous request to username.php. The function call will look something like this:</p> <pre><code>function lookupUsername(){ $.ajax({ type: "POST", url: "username.php", data: { ID: $("#userID").val() } }).done(function( msg ) { alert( "Username: " + msg ); }); } </code></pre> <p>In the above example, I've assumed that the user ID is embedded somewhere on your page in an element with <code>ID="userID"</code>. The term <code>$("#userID").val()</code> is a jQuery function that looks up the value of the HTML element called "userID".</p> <p>Next, you need to call the lookup function when the yes radio button is clicked. So something like:</p> <pre><code>&lt;input type="radio" name="foo" id="foo" value="yes" onclick="lookupUsername()" /&gt; </code></pre> <p>Note that to use the JQuery framework (The .ajax() function and the $() selector function, you need to include the JQuery framework on your page:</p> <pre><code>&lt;script src="http://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt; </code></pre> <p>It's totally possible to do an ajax call without jQuery, but the code is a little messier.</p>
    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.
 

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