I'm facing a problem to get return value (content-type: "text/xml"). I'm able to get return value by direct access this URL:
https://[domain_name]/myfolder/myapi/?xml=<xml version='1.0'><MyTasks><Search></Search></MyTasks>
Please help me to correct these alternatives if it is wrong (called in HTML located in MyFolder
) because it always alert 'Failed'.
$.ajax({
type : "GET",
url : "interface/?xml=<xml version='1.0'><MyTasks><Search></Search></MyTasks>",
dataType : "text/xml",
success : function(msg){
alert('Success');
}
error : function(msg) {
alert('Failed');
}
});
or...
$.ajax({
type : "POST",
url : "interface/",
data : { xml: escape("<MyTasks><Search></Search></MyTasks>") },
dataType : "text/xml",
success : function(msg){
alert('Success');
}
error : function(msg) {
alert('Failed');
}
});
Thank you.
SOLUTION
The interface has to be accessed by https
, so I changed url
param to absolute URL. I also have to use "xml"
not "text/xml"
as its dataType
. It results Success, thank you.
Does this take POSTs at all .. from your example, it looks like its setup for GETs.. Try this :
$.ajax({
type : "GET",
url : "http://blachblahblah.com/abc.html",
dataType : "text/xml",
data : { xml : escape("<xml version='1.0'><MyTasks><Search></Search></MyTasks>") },
success : function(msg){ alert('Success'); } ,
error : function(msg) { alert('Failed'); }
});
To simplify, I would do the following
Lets assume you are using a php script called script.php.
var xml_string = "<xml version='1.0'><MyTasks><Search></Search></MyTasks>";
$.get('script.php', {xml: xml_string}, function(){ //your success function
alert('success');
}).error(function(){ //your error function
alert("error");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With