Using ajax in jquery

This is how ajax works in jquery.. notice just how much easier it is than doing things with php! I hope you find my code and comments helpful


url: ‘../admin/quote-system-api/get-selected-options’, //THIS IS THE URL OF THE PHP SCRIPT YOUR POSTING TO, So the php script will take the data you send it using $_POST[”] array and query the database and return data back.
data: selectedOptionsData, // This is the data you are sending the php script, in this example that is a variable which will be in a format like this modelid=27&optionid=10, in the php script to get that you use $_POST[‘modelid’]; You need a php file that specifically accepts that variable.
// that is serialised data you get this usually in long urls eg catalogue id, colour id and size e.g.
statusCode: {
404: function(){
alert(‘There was an error’);
} // this is what happends if it doesn’t find the url to the php file
success: function(data){

// the php script should echo something out this part uses that data in the data variable
// refresh page
$(‘#additionalOptionsContainerB’).html(data); // this selects a div and inserts into the div the data from the php script, for example if the php script echos ‘this is a php script’ then those words will be inserted into that div
});// end ajax

// with ajax you cannot send data to any other domain but your own although there is a work around but dont concern yourself with this yet…


Leave a Reply

Your email address will not be published. Required fields are marked *