How to Avoid overwriting the current page after ajax-post-json-xhr requests to php

Source: Internet
Author: User
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('')

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.