Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Nov 2008
    Thanked 0 Times in 0 Posts

    problem in calling servlet from javascript using xmlhttpreq

    Hello Experts,
    I want to send xml data to servlet using xmlhttprequest object from a pure HTML Page.I have written some code but it is not working.One strange thing if I copy the same code in jsp & then run it , it is calling servlet from javascript & sending the xml data to it.I hope I am able to express my problem.Please Help.Thanx in advance.

    This is my code
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Page</title>
            <script type="text/javascript"> 
            var xmlHttp;
                function createXMLHttpRequest() {
                    if (window.ActiveXObject) {
                        xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                    else if (window.XMLHttpRequest) {
                        xmlHttp = new XMLHttpRequest();
                function doSyncResult() {
                    queryString ="http://localhost:8090/TestProject1/receiveXMLData";
                    var params = "xml=<cstore> <customer id='1'><name> Neha</name></customer> </cstore>";
                    xmlHttp.open("POST", queryString, true);
                    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
                    xmlHttp.setRequestHeader("Content-length", params.length);
                    xmlHttp.setRequestHeader("Connection", "close");
                    xmlHttp.onreadystatechange = handleStateChange;
                function handleStateChange() {
                    if(xmlHttp.readyState == 4) {
                        if(xmlHttp.status == 200) {
                            alert("results sync properly");               
            <input type="button" onClick="doSyncResult()">

  2. #2
    Senior Coder shyam's Avatar
    Join Date
    Jul 2005
    Thanked 163 Times in 160 Posts
    xmlhttp requests are sent to a server and hence require the code to be served out of a server...saving the code as a html file and calling the server isn't going to work
    You never have to change anything you got up in the middle of the night to write. -- Saul Bellow


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts