简体   繁体   中英

Ajax - How to print to console or something similar to Message box?

I am using the developers tools on google chrome to deconstruct a website. The website uses ajax to send 'Post' requests. I am trying to modify the ajax file to print certain variables in the ajax file but cant figure out how.

here is the code:

      function ajax_doRefresh(url, type, params, onloadFunction){

var xmlHttp;
try
{    
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();    
}
catch (e)
{   // Internet Explorer    
    try
    {      
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e)
    {      
        try
        {        
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {        
            alert("Your browser does not support AJAX!");        
            return false;        
        }      
    }    
}

var result = null;

xmlHttp.onreadystatechange=function()
{
    if(xmlHttp.readyState==4)  
    {
        if (xmlHttp.status==200) 
        {
            if(type != null && type.toUpperCase() == "XML")
                result = xmlHttp.responseXML;   
            else
                result = xmlHttp.responseText;

            if(onloadFunction != null && onloadFunction.length > 0)
            {
                var exe_func = onloadFunction + "(result)";
                eval(exe_func);
            }
            //alert(result);
        }
        else
            alert("Error retrieving data: status code = " + xmlHttp.status);
    }
}    

xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=UTF-8");
xmlHttp.send(params);

}

i want to be able to print to console/see the results of url, type, params, onloadFunction

This is a rewrite to replace the status 200 block using document.write to output text to the web page. I can also suggest inserting a document.write('url: ' + url + ' type: ' + type + ' params: ' + params + '<br>'); after the var xmlHttp line. As given, I don't think the onloadFunction output will tell you very much but its possible it will give something. You can probably use something like this to give you some more info about whats going on:

    if (xmlHttp.status==200) 
    {
        if(type != null && type.toUpperCase() == "XML")
            result = xmlHttp.responseXML;   
        else
            result = xmlHttp.responseText;

      document.write('result: ' + result + '<br>');

        if(onloadFunction != null && onloadFunction.length > 0)
        {
           document.write('onloadFunction: ' + onloadFunction + '<br>');
        }

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM