SoFunction
Updated on 2025-04-07

Difference between prototype and Ajax implementation under jquery

Let’s first list the implementation of Ajax in Jquery and prototype.
Jquery:
Copy the codeThe code is as follows:

<script language="javascript">
$(function(){
var box = {};
var remoteUrl = '';
= 5*60*1000;//5 minutes
= function() {
(remoteUrl, function(data){
var msg_box = $('#msg_box');
msg_box.innerHTML = data;
}
});
}
= function(){
();
setInterval(,);
};
();
})
</script>

prototype:
Copy the codeThe code is as follows:

<script language="javascript">
var box = {};
= 5*60*1000;//5 minutes
= function(){
var pars = "";
var remoteUrl = '';
var myAjax = new (
remoteUrl,
{
method: 'get',
parameters: pars,
onComplete:
});
};
= function(data){
var msg_box = $("msg_box") ;
msg_box.innerHTML = ;
};
= function(){
();
setInterval(,);
};
();
</script>

In fact, the prototype cannot be refreshed after introducing the setInterval function. Why is this?
It turns out that prototype has a cache mechanism for the same URL, so the page should not be refreshed. Especially after the user uses F5 or clicks "Refresh", a blank bug will appear in the Ajax response area, so the prototype must not be refreshed.
Add a random number for URLs in prototype
Original: var remoteUrl = '';
After modification: var remoteUrl = '?rand='+();
Use the GET method to generate a parameter that is not related to the page display.