0

My program is giving me an error from jquery. I don't understand why. I works in c# but in jquery it does not

using (XmlTextWriter writer = new XmlTextWriter(new StringWriter(sb)))
            {
                writer.Formatting = System.Xml.Formatting.Indented;
                ser.Serialize(writer, ct);
                XMLContent = sb.ToString();
            }
            return Content(XMLContent, System.Net.Mime.MediaTypeNames.Text.Xml);

f

$.ajax(
        {
            type: "POST",
            url: action,
            data: formobj,
            dataType: "xml",
            success: function(result) {
                alert(result);
            },
            error: function(req, status, error) {
                alert(req.statusText);
            }
        });
        return false;

When I replace

return Content(XMLContent, System.Net.Mime.MediaTypeNames.Text.Xml);

with

return Content(XMLContent);

and remove

dataType: "xml",

from jquery it all works.

1
  • In the JQuery Ajax Part the req.statusText value returns OK. So I am stumped on what it could be Commented Nov 16, 2009 at 7:45

1 Answer 1

2

One way that could simplify and optimize your ajax a lot, is to use JSON instead of XML.

(unless you really want your result to be XML)

In ASP.Net MVC you can let your Action return Json as result.

return Json(new {
    variableName: someData,
    anotherVariableName: someMoreData
});

In your Js:

$.post(
    'yourActionName',
    optionalData,
    function(d) {
        alert(d.variableName);
        alert(d.anotherVariableName);
    }
);

Couldn't be more simple than this :)

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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.