I code on the side, and I pulled out some old websites I built with a friend to get working again. I haven't done any AJAX for a while and as I try to figure out where my code is failing, I am finding that there are not a lot of resources showing up. I am guessing that it is because I am using old methods. I am trying to see if there is a quick change to my approach I should consider, or whether somebody knows a way to work with what I have to find the problem. These webpages use jQuery 1.4.4, so quite old.
Here is my old code:
var ajaxRequest = getAjaxRequest();
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4) {
document.getElementById("apple").style.display = "block";
setTimeout(function(){ document.getElementById("apple").style.display = "none"; },2000);
}
}
ajaxRequest.open("GET", "url.php" + encodeURIComponent(appleObject), true);
ajaxRequest.send(null);
I am seeing a lot of code more like:
$.ajax({
type: "GET",
url: "url.php",
success: function(something){
something
}
});
My goal is to use the "success" or "onSuccess" to make sure the page was found and console.log something returned from the php file if possible.
Questions:
-Is my method a security problem, needing major update?
-If so, am I just going to need to bite the bullet and update jQuery, too?
-If not, can somebody suggest how I can do some form of "success" call using my existing code? i.e. something like: ajaxRequest.success(console.log(something));