CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Ajax and Design (http://www.codingforums.com/forumdisplay.php?f=55)
-   -   HTTP Post Request and Response Displaying Problem (http://www.codingforums.com/showthread.php?t=284321)

navybofus 12-18-2012 05:56 AM

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.

Fou-Lu 12-18-2012 01:38 PM

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.

devnull69 12-18-2012 02:51 PM

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 :-)

navybofus 12-18-2012 09:41 PM

Quote:

Originally Posted by devnull69 (Post 1300789)
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 (Post 1300789)
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.

AndrewGSW 12-18-2012 09:57 PM

What are the little stars for? Are they snowflakes..?


All times are GMT +1. The time now is 05:48 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.