Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 585
  • Last Modified:

Not Receiving XML Response From JQuery XML Post

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
joshaxton
Asked:
joshaxton
  • 2
  • 2
1 Solution
 
leakim971PluritechnicianCommented:
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
 
joshaxtonAuthor Commented:
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
 
joshaxtonAuthor Commented:
It would've been better if the alternative solutions was presented in detail with coding examples than simply posting a link.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now