Solved

Not Receiving XML Response From JQuery XML Post

Posted on 2011-03-09
4
551 Views
Last Modified: 2012-05-11
I want to use JQuery AJAX to send the below XML document and receive in response an XML document.  The problem is when I receive the response it comes across as successful but the data is blank.  I am using Javascript JQuery to handle both the request and following response.

XML Document
<?xml version="1.0" encoding="utf-8"?>
	<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
		<soap:Body>
			<GetRates xmlns="http://www.notavailable.com/notavailable/">
				<objGetRatesRequest>
					<UserId>notavailable</UserId>
					<Password>notavailable</Password>
					<TpaCode>DEMO</TpaCode>
					<DealerNo>DEMO001</DealerNo>
					<NewUsed>U</NewUsed>
					<VIN>WBABN53463PH03667</VIN>
					<VehiclePurchasePrice>24990</VehiclePurchasePrice>
					<VehicleOdometer>19456</VehicleOdometer>
					<SaleDate>2011-05-26T00:00:00</SaleDate>
				</objGetRatesRequest>
			</GetRates>
		</soap:Body>
	</soap:Envelope>

Open in new window


Javascript JQuery Code
$.get('ajax/getRequest.php', function(xmlDoc) { 
				alert(xmlDoc)
				$.ajax({
					url: "https://uat825.notavilable.com/notavailable.webservice/notavailable.asmx",
					processData: false,
					type: "POST",
					data: xmlDoc,
					success: function(data, status) {alert(status);alert(data)}
				});			
			});		

Open in new window

0
Comment
Question by:joshaxton
  • 2
  • 2
4 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 35089647
You can't do cross-domain/protocol ajax call.
It seems it's your case here.
The page used to post or get the data need to be on the same domain and use the same protocol than the page which receive or send the data.

You need to use a proxy, JSONP, or others technics to achieve your goal
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35089748
0
 

Author Comment

by:joshaxton
ID: 35112510
Thanks for your response.  It provided me enough information to create the solution.  Below is the end result snippet of code I am returning to the client.  This works perfectly on a Windows 2008 Server PHP Environment.

<?php
session_start();
include_once "../inc/dbcon.php";
include_once "../inc/globals.php";
include_once "../inc/constants.php";

$VIN= $_REQUEST["VIN"];
$VehicleOdometer= $_REQUEST["VehicleOdometer"];
$NewUsed = $_REQUEST["NewUsed"];
$VehiclePurchasePrice= $_REQUEST["VehiclePurchasePrice"];
$DealerNo= $_REQUEST["DealerNo"];
$SaleDate= date("Y-m-d")."T00:00:00";

$con = getDBConn();
$xmlString = '<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetRates xmlns="http://www.notavailable.com/notavailable/">
<objGetRatesRequest>
<UserId>notavailable</UserId>
<Password>notavailable</Password>
<TpaCode>notavailable</TpaCode>
<DealerNo>'.$DealerNo.'</DealerNo>
<NewUsed>'.$NewUsed.'</NewUsed>
<VIN>'.$VIN.'</VIN>
<VehiclePurchasePrice>'.$VehiclePurchasePrice.'</VehiclePurchasePrice>
<VehicleOdometer>'.$VehicleOdometer.'</VehicleOdometer>
<SaleDate>'.$SaleDate.'</SaleDate>
</objGetRatesRequest>
</GetRates>
</soap:Body>
</soap:Envelope>';

define('XML_PAYLOAD', $xmlString);
define('XML_POST_URL', 'https://uat825.notavailable.com/notavailable.webservice/notavailable.asmx');

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, XML_POST_URL); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 4); 
curl_setopt($ch, CURLOPT_POSTFIELDS, XML_PAYLOAD); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml','Connection: close'));
	
$start = array_sum(explode(' ', microtime()));
$result = curl_exec($ch); 
$stop = array_sum(explode(' ', microtime()));
$totalTime = $stop - $start;

if ( curl_errno($ch) ) {
	$result = 'cURL ERROR -> ' . curl_errno($ch) . ': ' . curl_error($ch);
} else {
	$returnCode = (int)curl_getinfo($ch, CURLINFO_HTTP_CODE);
	switch($returnCode){
		case 200:
			break;
		default:
			$result = 'HTTP ERROR -> ' . $returnCode;
			break;
	}
}	

curl_close($ch);

echo 'Total time for request: ' . $totalTime . "\n";
echo $result;   

sqlsrv_close($con); 
?>

Open in new window

0
 

Author Closing Comment

by:joshaxton
ID: 35112522
It would've been better if the alternative solutions was presented in detail with coding examples than simply posting a link.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
file upload jquery, send variables 3 26
PHP AJAX JSON 2 61
CSS: Making Pure CSS read more boxes thinner 5 31
Diminish Pop-up  in 3 seconds 7 23
Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question