bharath
bharath

Reputation:

how to pass xml as parameter using POST method and using jquery ajax

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?

Upvotes: 13

Views: 18125

Answers (1)

ryanrdl
ryanrdl

Reputation: 413

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);

Upvotes: 18

Related Questions