What if you did:
$("#container").load("data.php?fname=" + firstname + "&lname=" + lastname);
Instead of:
$.ajax({
url: 'data.php',
data: 'fname=' + firstname + '&lname=' + lastname,
type: 'GET',
success: function(data) {
$("#container").html(data);
}
});
If all you were doing was echoing the data:
<?php
print_r($_GET);
?>
Sorry if I am not understanding something basic, but is there a reason to use one over the other if they both produce the same result?
Well, in the end, .load() uses $.ajax() to make the request.
The actual role of .load() is to set the content of the matched elements to the data received in case of a successful request. It also allows loading page fragment by appending a selector after the actualy url, like this:
The load() method executes a GET request by default. Note that the method takes an optionnal second parameter
datato pass data. In this case, it executes a POST request.