Replace current page with ajax content

前端 未结 9 1272
南旧
南旧 2020-12-05 04:50

I have a page with a dialog window which sends ajax post data to server and receives a response. During development, there can be two responses - one regular (this is not th

9条回答
  •  误落风尘
    2020-12-05 05:15

    Here is an example of how to change either if the response is a url or a html content (using django\php)

            var xmlhttp;
            xmlhttp=new XMLHttpRequest();
    
            xmlhttp.onreadystatechange=function()
            {
                var replace_t = '{{ params.replace_t }}';
                if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                    if(replace_t == 'location')
                        window.location.replace(xmlhttp.responseText);
                    else if(replace_t == 'content')
                    {
                        document.open();
                        document.write(xmlhttp.responseText);
                        document.close();
                    } 
                }
            }
    
            xmlhttp.open("GET",SOME_ASYNC_HANDLER_URL,true);
            xmlhttp.send();
    

提交回复
热议问题