?
Solved

Not Receiving XML Response From JQuery XML Post

Posted on 2011-03-09
4
Medium Priority
?
571 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1500 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

762 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