简体   繁体   中英

xmlHttpRequest.send(Params) not working in tomcat 7

I am trying to send some parameters through xmlHttpRequest.send(params) written in a JS file to my servlet where I try to get the parameters by req.getParameter("some_Parameter"); it returns null on the servlet. though if i send the parameters by appending them in url it works fine. but when the url will be large it will break the code. so please someone help me out.

Thanks in advance.

function doHttpPost(theFormName, completeActivity) 
{ 
    var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP"); 
    var xmlMessage = buildPOST(theFormName, completeActivity); 
    var responseTxt; 
    try { 
        xmlhttp.Open(document.forms[theFormName].method, document.forms[theFormName].action+'?'+xmlMessage, false); 
        xmlhttp.onreadystatechange=function() { 
            if (xmlhttp.readyState==4) { 
                responseTxt = xmlhttp.responseText; 
            } 
        } 
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        enableDisableLinks(true);
        setPointer();  
        xmlhttp.Send(); 
        if(xmlhttp.Status != 200) { 
            alert("Post to server failed"); 
        } 
    } catch (e) { 
        responseTxt = "Exception while posting form data: Error No: " + e.number + ", Message: " + e.description; 
    } 

    resetPointer();  
    enableDisableLinks(false);
    var expectedTxt = "Form Data had been successfully posted to the database." 
    if(responseTxt.toString() == expectedTxt.toString()) { 
        // MNP: New requirement from Jeanne, should not refresh CM page, commenting it off for now
        //if(completeActivity) {
        //  if (typeof (ViewCaseDetailBtn) != 'undefined') {
        //      ViewCaseDetailBtn.click();
        //  }
        //}
        return true; 
    } else {
        alert (responseTxt); 
    }
    return false; 
}

BUGS

//IE only - shooting yourself in the
// Not all IE versions use ActiveX!
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");    foot. 

//JavaScript case sensitive, open !== Open
xmlhttp.Open(document.fo...

//JavaScript case sensitive, send !== Send
xmlhttp.Send();

//JavaScript case sensitive, status !== Status
xmlhttp.Status

AND if you are using synchronous, it does not call the onreadystatechange.

If you are using POST, the value needs to be in send("valuestosendup") not on the querystring.

This code shows why you should really use a framework to make Ajax calls and to not roll your own.

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