For example, when I use js to send a request to php and load the response to the current page, how can I avoid overwriting the current page? The specific situation is as follows: js: {code ...} themesticketmodelechoNav. php returns an array of stringized json; then it obtains me... for example, when Javascript is used to send a request to php and load the response to the current page, how can we avoid overwriting the current page;
The specific situation is as follows:
Js:
var navLst = {};var reqInfo = {};reqInfo['reqNav'] = true;reqInfo['reqSin'] = 'qtrfss'; //more limt options would be addedvar reqSent= JSON.stringify(reqInfo);var xhr = null;if(window.XMLHttpRequest){ xhr = new XMLHttpRequest();}else{ xhr = ActiveXObject('Microsoft.XMLHttp');}xhr.open('POST', '/themes/ticket/model/echoNav.php',true);xhr.onreadystatechange=function(){ if(xhr.readyState == 4) { if(xhr.status == 200) { try{ var resp = eval('('+ xhr.responseText +')'); listMenu(resp); }catch(e){ listMenu(e); } } else { //undo } }};xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');xhr.send('reqSent='+reqSent);
/Themes/ticket/model/echoNav. php returns an array of stringized json;
Then the menlist is obtained. During the rewriting, only menulist is left on the page...
Listmenu:
Function listMenu (menuLst ){
// Var menuLst = ['sci-Fi ', 'home', 'wiki']; // menu lst shoshould come from phpvar nav = ''; var navIE = ''+' '; var navStyle = ''; // stylesheet's urlnav + = navIE; nav + = navStyle; nav + =''; document. write (nav); var navUl = document. createElement ('ul '); navUl. id = 'onav _ bar'; var navLst = ''for (var I = 0; I <= menuLst. length-1; I ++) {var navLi = document. createElement ('lil'); var achor = document. createElement ('A'); if (I = 0) {navLi. className = 'onav _ top onav_logo '; achor. setAttribute ('href ',' # '); var spanX = document. createElement ('span '); spanX. className = 'onav _ yellow'; spanX. innerHTML = 'sci-Fi '; achor. appendChild (spanX); var spanY = document. createElement ('span '); spanY. className = 'onav _ white'; spanY. innerHTML = '.. Net '; achor. appendChild (spanY);} else {navLi. className = 'onav _ top'; achor. setAttribute ('href ',' # '); achor. setAttribute ('target', '_ blank'); achor. setAttribute ('title', menuLst [I]); achor. innerHTML = menuLst [I];} navLi. appendChild (achor); navUl. appendChild (navLi) ;}; var navDiv = document. getElementById ('onav _ wrapper '); navDiv. appendChild (navUl); // need to be briefvar oAhor = document. getElementById ('onav _ bar '). getElementsByTagName ('A'); for (I = 0; I
Solution:
Yesdocument.write(nav);, DOM loaded and reuseddocument.write()The method overwrites the previous content. Test and replace the method in the functiondocument.write('')