2011-09-24, 08:25 PM
Today I decided to upgrade the javascript in DNP Script to use jQuery which meant I had to sit down and learn the syntax (which it turns out isn't very complicated). It's been amazing seeing how much less you have to write using jQuery.
This was the most notable enhancement so far. I turned these two javascript functions used to submit a form using Ajax:
into this function:
This was the most notable enhancement so far. I turned these two javascript functions used to submit a form using Ajax:
function submitForm() {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
if(xmlhttp.responseText == "<span class=\"message_success\">Congratulations! You\'ve successfully installed DNP Script. You should remove the /install directory from your server now. After that I recommend you get started in the <a href=\"../admin/\">Admin Panel</a> to configure the site. Thanks for using DNP Script!</span>"){
var e = install.elements;
for(i=0;i<e.length;i++){
e[i].disabled = true;
}
document.getElementById("database_test").innerHTML="";
document.getElementById("submit_section").innerHTML="";
}
document.getElementById("form_message").innerHTML=xmlhttp.responseText;
document.getElementById("pass_match").innerHTML="";
}
}
xmlhttp.open("POST", "install.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send(queryString());
}
function queryString() {
var e = install.elements;
for ( i = 0; i < e.length; i++ ) {
if ( i == 0 ){
var qstr = e[i].name+"="+encodeURIComponent(e[i].value);
}
else {
qstr = qstr+"&"+e[i].name+"="+encodeURIComponent(e[i].value);
}
}
return qstr;
}
into this function:
function submitForm() {
$.post('install.php', $('#install').serialize(), function(response) {
if ( response == "<span class=\"message_success\">Congratulations! You\'ve successfully installed DNP Script. You should remove the /install directory from your server now. After that I recommend you get started in the <a href=\"../admin/\">Admin Panel</a> to configure the site. Thanks for using DNP Script!</span>" ) {
var e = install.elements;
for(i=0;i<e.length;i++){
e[i].disabled = true;
}
$("#database_test").html("");
$("#submit_section").html("");
}
$("#pass_match").html("");
$("#form_message").html(response);
});
}