1

I'm trying to replace an ajaxpro script with jQuery, but the response i'm getting from the server when using either ajaxpro or jquery is something i don't recognise.

This is the jquery call:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/ajaxpro/CMS.ItemRetrieve.ashx",
    data: jsonData,
    beforeSend: function(xhr) {
        xhr.setRequestHeader("X-AjaxPro-Method", "ItemRetrieve");
        xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
    },
    success: function(responseText) {
        console.log(responseText);
    }
})

And this is the weird response:

[0,"\r\n\r\n<div id=\"content\">test</div>\r\n "];/*

I'm expecting HTML or XML in return, but this seem to be an array? I don't understand the escaping and wierd end. I tried setting dataType to json, but it's not json, not html, maybe javascript? Server response content-type seem to be set to text.

So my question is, how do i use this response as HTML, or convert it to HTML?

4

1 回答 1

1

如果不指定dataType,jQuery 会对它从 AJAX 调用返回的数据格式进行最佳猜测。90%的时候是对的。其他时候它需要一点帮助。

尝试这个:

$.ajax({
    type: "POST",
    contentType: "application/json; charset=utf-8",
    url: "/ajaxpro/CMS.ItemRetrieve.ashx",
    data: jsonData,
    dataType: "html", // Explicitly set the return data type
    ...
});

更多信息在这里

于 2011-11-25T15:19:06.497 回答