I have a very simple PHP form which posts XML data to a URL, which then responds with more XML. Here it is:
form action="[...]" method="POST">
<textarea name="xml" rows="30" cols="100">
<RRequest version = '2.13'>
<Request>
<Command>update</Command>
<Pd>
<RID>1</RID>
<ExtID>111111111</ExtID>
</Pd>
</Request>
</RRequest>
</textarea>
<br>
<input value="Submit Request" type="submit">
</form>
This works beautifully. I am attempting to implement the same thing, but using jQuery. Here is that code:
<script>
$(document).ready(function() {
$("#submit").click(function(){
var xml_data = $("#xml").val();
$.ajax({
type: "POST",
url: "[...]",
data: xml_data,
contentType: "text/xml",
dataType: "text",
cache: false,
success: function(data){
$("#xml").val("");
$("#xml").val(data);
},
error: function(xhr, textStatus, errorThrown){
alert("it no works");
}
});
});
});
</script>
</head>
<body>
<textarea id="xml" rows="30" cols="100">
<RRequest version = '2.13'>
<Request>
<Command>update</Command>
<Pd>
<RID>1</RID>
<ExtID>111111111</ExtID>
</Pd>
</Request>
</RRequest>
</textarea>
<br>
<input type="button" id="submit" />
This, however, does not work. It does contact the server, but the server returns a bad request message, which makes me think the data being sent is not correct. The two textareas containing the XML are identical. Any help would be greatly appreciated.
I am using jQuery 2.1.3.