PDA

View Full Version : jQuery Sending XML via $.ajax, but specifing POST name.


dniwebdesign
01-20-2010, 04:05 AM
Don't know if the title made any sense, but here's my problem.
I have the following code:
$.ajax({
//url: "http://sellonline.canadapost.ca:30000"
url: "test.php"
, type: "POST"
, processData: false
, data: xmlDocument
, success: function(responsed) {
alert("Returned\n---------------------\n"+responsed);
}
, error:function(xhr,err){
alert("readyState: "+xhr.readyState+"\nstatus: "+xhr.status+"\ntext: "+xhr.statusText);
alert("responseText: "+xhr.responseText);
}

});
Which, at present time works fine... the test.php only has <?php
print_r($_POST);
?>
which again works fine. Returns the xml document in the $_POST array that I sent.

However, I need to send this with the key "XMLRequest". As if the XML was in a textarea with name="XMLReqeust".
Basically, I want to do what they do here. http://sellonline.canadapost.ca/DevelopersResources/protocolV3/HTTPInterface.html Only via AJAX, which should work, no?

I've tried data: ({ 'XMLRequest': xmlDocument }) but with no success.

Is there any way to do this. I've tried searching the jQuery API but they're very limited on how this works. Thanks.

Fumigator
01-20-2010, 04:43 PM
Isn't the format data: "name=value"? So in your case, this should work:


, data: "XMLRequest=" + xmlDocument