I want to call pages via ajax php with this plugin. Can anyone tell me how to do this, I want examples of how to call contents in different divs
To post this question I used Google Translator.
I want to call pages via ajax php with this plugin. Can anyone tell me how to do this, I want examples of how to call contents in different divs
To post this question I used Google Translator.
Probably you do not need a plugin to do AJAX. You can easily learn AJAX by yourself. At first it might look a little challenging, but AJAX is much easier than you may think.
First, note that AJAX is generally used to send data to the SERVER, get the server to process that data (for example, look up info in database) and return new data to the browser. Therefore, AJAX should not be used to call an HTML file, but usually a PHP or ASP file that can do things on the server.
Ajax goes in your javascript code, and looks like this:
HTML:
<select id="stSelect">
<option>Harold Windsor</option>
<option>Catherine Middleton</option>
<option>Bill Williams</option>
<option>Jane Peters</option>
</select>
JAVASCRIPT/JQUERY:
$('#stSelect').change(function() {
var sel_stud = $(this).val();
//alert('You picked: ' + sel_stud);
$.ajax({
type: "POST",
url: "your_php_file.php",
data: 'theOption=' + sel_stud,
success: function(whatigot) {
alert('Server-side response: ' + whatigot);
} //END success fn
}); //END $.ajax
}); //END dropdown change event
Note that the data from the PHP file comes into your HTML document in the success function of the AJAX call, and must be dealt with there. So that's where you insert the received data into the DOM.
For example, suppose your HTML document has a DIV with the id="myDiv"
. To insert the data from PHP into the HTML document, replace the line: alert('Server-side response: ' + whatigot);
with this:
$('#myDiv').html(whatIgot);
Presto! Your DIV now contains the data echoed from the PHP file.
The ajax can be triggered by a change to an control's value (as in the above example), or just at document load:
$(function() {
//alert('Document is ready');
$.ajax({
type: "POST",
url: "your_php_file.php",
data: 'Iamsending=' + this_var_val,
success: function(whatigot) {
//alert('Server-side response: ' + whatigot);
} //END success fn
}); //END $.ajax
}); //END document.ready
Look at this example for ideas on how it works.
Note that the above examples use jQuery, and therefore require this reference in the tags of your page:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
</head>