如何使用POST方法和jquery ajax将xml作为参数传递 [英] how to pass xml as parameter using POST method and using jquery ajax
本文介绍了如何使用POST方法和jquery ajax将xml作为参数传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery + ajax将数据发布到服务器,并且在传递xml字符串时遇到了问题.
我想使用POST方法将xml字符串(例如"<test></test>
")作为参数传递给ajax函数.
我能够传递所有其他类型,但不能传递xml字符串.
I am using jQuery + ajax to post data to the server and facing issues when xml string is passed.
I want to pass xml string eg., "<test></test>
" as a parameter to the ajax function using POST method.
i am able to pass all other types, but not xml string.
有人可以帮我吗?
推荐答案
要将xml或html发布到服务器,您必须先转义,然后解码 >在服务器上.
In order to post xml or html to the server, you first have to escape it and then decode on the server.
$.ajax({
type: "POST",
url: "Home/GetResults",
data: {
inputxml: escape('<test></test>')
},
success: function(msg) {
var data = JSON.parse(msg);
alert(data.Message);
},
});
在服务器上,您可以通过以下方式对其进行解码:
on the server, you would then decode it by:
HttpUtility.UrlDecode(inputxml);
这篇关于如何使用POST方法和jquery ajax将xml作为参数传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文