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

    Question HTTP Post Request and Response Displaying Problem

    I've been working on a bit of code for a while now and I finally got it to work by testing it in an HTML file locally. I'm using an HTTP Post to send information to a sever that is set up to send a response back to me. I am using the following code to send the required fields, but it doesn't want to display the response in my DIVs after I've uploaded it to my web hosting. I have some PHP modules installed that should allow the XMLHttpRequest to work (HTML_Ajax and some others.) Basically I need a new set of eyes to look at this and see if there are any errors, or if I need to ask another question: "Why isn't my web hosting allowing my to show my responseText when it says that Ajax is compatible?"

    Code:
    <!DOCTYPE html>
    <html>
    <head>
    <script>
    function loadXMLDoc()
    {
    	var xmlhttp;
    	var response;
    	if (window.XMLHttpRequest)
    		{// code for IE7+, Firefox, Chrome, Opera, Safari
    			xmlhttp=new XMLHttpRequest();
    		} else {// code for IE6, IE5
    			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		
    	xmlhttp.onreadystatechange=function()
    	{
    		if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{             
    			response = xmlhttp.responseText; //Just showing a friend how variables work 
    			document.getElementById("myDiv").innerHTML=response;
     *  	}
    	}
    	
    	xmlhttp.open("POST","http://www.ssicat.com/smart/Updates.asmx/ActiveItemCount",false);
    	xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp.send("CustomerNumber=99994&UserName=99994&Password=71115&Source=99994");
    
    	var xmlhttp1;
    	
    	if (window.XMLHttpRequest)
    	{// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp1=new XMLHttpRequest();
    	} else {// code for IE6, IE5
    		xmlhttp1=new ActiveXObject("Microsoft.XMLHTTP");
    	}
    
    	xmlhttp1.onreadystatechange=function()
    	{
    		if (xmlhttp1.readyState==4 && xmlhttp1.status==200)
    		{
    			document.getElementById("myDiv1").innerHTML=xmlhttp1.responseText;
     *  	}
    	}
    
    	xmlhttp1.open("POST","http://www.ssicat.com/smart/Updates.asmx/GetItemDetails",true);
    	xmlhttp1.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    	xmlhttp1.send("CustomerNumber=99994&UserName=99994&Password=71115&Source=99994&ItemNumber=3301");
    }
    </script>
    </head>
    
    <body onload="loadXMLDoc()">
    
    <h2>TEST TEST</h2>
    
    <div id="myDiv"></div>
    <div id="myDiv1"></div>
    
    </body>
    
    </html>
    Oh and that password is setup for testing, so no biggie. Thanks is advance.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Your webhost won't be doing anything. This hasn't a thing to do with server side languages, this is AJAX so it is governed completely by the client.
    Since this has nothing to do with PHP, and the script you are attaching to is ASP anyways, moving to AJAX forum.

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    Several questions:

    1 - Did you intentionally put "false" as a third paramter to .open()? You should immediately set it to "true"
    2 - Is http://www.ssicat.com the same domain, sub domain and protocol the current page has been served from? I am asking this because otherwise it would be a cross domain request that would require the server to send a specific resonse header (Access-Control-Allow-Origin) in order to allow requests from other origins :-)

  • #4
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by devnull69 View Post
    Several questions:

    1 - Did you intentionally put "false" as a third paramter to .open()? You should immediately set it to "true"
    Yes that was me playing around with it and forgetting to change it back. I have changed it back and the problem persists.

    Quote Originally Posted by devnull69 View Post
    2 - Is http://www.ssicat.com the same domain, sub domain and protocol the current page has been served from? I am asking this because otherwise it would be a cross domain request that would require the server to send a specific resonse header (Access-Control-Allow-Origin) in order to allow requests from other origins :-)
    No, we are sending the request to another server and I believe that the specific response headers are being sent and specific headers are also being received as this server is made to allow us access to their database to make updates to our database.

    We received extremely little help (for beginners) from the distributor. They gave us this site: http://www.ssicat.com/smart/Updates....GetItemDetails and that was basically it.

    I guess I really am just looking for a way to use either HTTP Post or SOAP. Although, I don't really understand SOAP either. Any help is greatly appreciated.

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    What are the little stars for? Are they snowflakes..?
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


  •  

    Tags for this Thread

    Posting Permissions

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