13

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.

Can somebody pls help me on this?

1
  • Adding the code snippet $.ajax({ type: "POST", url: "Home/GetResults", data: { inputxml: '<test></test>'}, success: function(msg) { var data = JSON.parse(msg); alert(data.Message); }, }); Commented May 28, 2009 at 9:56

1 Answer 1

18

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.