How can i post combined variable and xml data using jquery ajax for webservice -
i new in ajax, xml , web service. want post http request call webservice variable values , xml data following format:
x=sender&b=receiver&xmlinput=<request><data1>100</data1><data2>200</data2></request>
here ajax code:
//these parameters var = 'sender'; var b = 'receiver'; var xmlinput = '<request><data1>$('#inputdata1').val()</data1><data2>$('#inputdata2').val()</data2>'; $.ajax({ url: 'webservice.php', type: "post", async: true, data: "a&b&xml" , datatype: 'xml', contenttype: "text/xml", success: function(xmldata){ }, error: function(jqxhr, textstatus, errorthrown) { console.log(textstatus, errorthrown); } });
please me that.thanks.
there couple of things need into. in javascript use +
operator concatenating strings andcontenttype: "text/xml"
means javascript expects data
value in xml format.
note : unlike in php, using variable name in single quoted string, doesn't processed javascript. it's treated simple string.
var = 'sender'; var b = 'receiver'; var xmlinput = '<request><data1>' + $('#inputdata1').val() + '</data1><data2>' + $('#inputdata2').val() + '</data2>'; $.ajax({ url: 'webservice.php' , type: "get", async: true, data: { xml : xmlinput, a: a, b: b }, datatype: 'xml', contenttype: "text/xml", success: function(xmldata){ }, error: function(jqxhr, textstatus, errorthrown) { console.log(textstatus, errorthrown); } });
Comments
Post a Comment