Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-18-2012, 05:56 AM   PM User | #1
navybofus
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
navybofus is an unknown quantity at this point
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.
navybofus is offline   Reply With Quote
Old 12-18-2012, 01:38 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,741
Thanks: 4
Thanked 2,465 Times in 2,434 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
Fou-Lu is offline   Reply With Quote
Old 12-18-2012, 02:51 PM   PM User | #3
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
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 :-)
devnull69 is online now   Reply With Quote
Old 12-18-2012, 09:41 PM   PM User | #4
navybofus
New to the CF scene

 
Join Date: Dec 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
navybofus is an unknown quantity at this point
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.
navybofus is offline   Reply With Quote
Old 12-18-2012, 09:57 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Tags
ajax, php, xmlhttprequest

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:31 PM.


Advertisement
Log in to turn off these ads.