-5

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.

marcos
  • 1
  • 1
  • 2
    Sorry, but we can't read this translation. Google Translator did a horrible job. – Philip Giuliani Jun 25 '13 at 14:08
  • 2
    Ajaxy documentation says to refer to the source code. If you are unable to understand the code then probably you don't need that plugin but a plain jquery ajax request with $('.something').load or $.get. – Mir Jun 25 '13 at 14:09
  • I know make a ajax request, but I need to know how to configure the plugin to make an ajax call – marcos Jun 25 '13 at 20:00

1 Answers1

1

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>
Community
  • 1
  • 1
cssyphus
  • 37,875
  • 18
  • 96
  • 111
  • I want to know how to manipulate the plugin jquery ajaxy because I did not understand how to call a file with this plugin – marcos Jun 25 '13 at 19:57