11.07.2015 Views

AJAX and PHP

AJAX and PHP

AJAX and PHP

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>AJAX</strong> Grid// h<strong>and</strong>le receiving the server response with a new page of productsfunction h<strong>and</strong>leGridPageLoad(){// when readyState is 4, we read the server responseif (xmlHttp.readyState == 4){// continue only if HTTP status is "OK"if (xmlHttp.status == 200){// read the responseresponse = xmlHttp.responseText;// server error?if (response.indexOf("ERRNO") >= 0|| response.indexOf("error") >= 0|| response.length == 0){// display error messagealert(response.length == 0 ? "Server serror." : response);// exit functionreturn;}// the server response in XML formatxmlResponse = xmlHttp.responseXML;// browser with native functionality?if (window.XMLHttpRequest && window.XSLTProcessor &&window.DOMParser){// load the XSLT documentvar xsltProcessor = new XSLTProcessor();xsltProcessor.importStylesheet(stylesheetDoc);// generate the HTML code for the new page of productspage = xsltProcessor.transformToFragment(xmlResponse, document);// display the page of productsvar gridDiv = document.getElementById(gridDivId);gridDiv.innerHTML = "";gridDiv.appendChild(page);}// Internet Explorer codeelse if (window.ActiveXObject){// load the XSLT documentvar theDocument = createMsxml2DOMDocumentObject();theDocument.async = false;theDocument.load(xmlResponse);// display the page of productsvar gridDiv = document.getElementById(gridDivId);gridDiv.innerHTML = theDocument.transformNode(stylesheetDoc);}}else{alert("Error reading server response.")}}}// enters the product specified by id into edit mode if editMode is true,// <strong>and</strong> cancels edit mode if editMode is falsefunction editId(id, editMode){// gets the element of the table that contains the tablevar productRow = document.getElementById(id).cells;// are we enabling edit mode?if(editMode){// we can have only one row in edit mode at one time214

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!