JQuery AJAX调用返回:好的

时间:2014-07-10 13:39:19

标签: jquery asp.net-mvc

ajax响应是:好的。这是代码:

<script type='text/javascript'>
$(document).ready(function () {
    $("button").click(function () {
        alert('Test');


        $('#div1 h2').text('Test');
        var divToBeWorkedOn = "#div1";
        var n1 = 1;
        var n2 = 2;
        var webMethod = "AJAXTest.html";
        $.support.cors = true;
        $.ajax({
            type: "GET",
            url: webMethod,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                $(divToBeWorkedOn).html(result.text);
            },
            error: function (e) {
                $(divToBeWorkedOn).html(e.statusText);
            }
        });



    })
});
</script>

AJAXTest.html包含以下文本:测试。因此,我希望div1内容更改为:Test。但是,它变为:好的。我做错了什么?

1 个答案:

答案 0 :(得分:1)

将数据类型json更改为html

   $.ajax({
        type: "GET",
        url: 'webMethod',
        contentType: "application/json; charset=utf-8",
        dataType: "html",
        success: function (result) {
            jQuery("#div_id").html(result);
        },
        error: function (e) { }
    });

试试吧,