为什么我的ajax电话不起作用?

时间:2015-06-01 06:57:10

标签: ajax asp.net-mvc asp.net-mvc-5 asp.net-ajax

我无法检测为什么我的ajax调用不起作用。我试图读取文本文件的内容,但它不起作用,问题是控件永远不会去.done(函数(数据))

 function makeCustomerTree()
    {
       // debugger
        alert('customertree');
        $.ajax(
            {
            url:"~/bootstrap/js/LiveMap/Ajax/JsonStringCarryingData/customer-tree-json.txt",
            data: {},
            type: "GET"
        }).done(function (data)
        {
            alert('done');
            $('#tree_loader').html('');
            tree = $.fn.zTree.init($("#customerTree"), setting, data);
            tree = $.fn.zTree.getZTreeObj("customerTree");
        }).fail(function (jqXHR)
        {
            alert('fail');
            $('#tree_loader').html('<font color="red">Unable to load.</font>');//jqXHR.responseText);
        });
    }

我的文件customer-tree-json.txt包含如下内容:

    [
    {
        "icon": "/static/tree/icons/user-20.png", 
        "pId": 7, 
        "id": 18, 
        "itemType": "lcustomer", 
        "name": "sachin bhatia"
    }, 
    {
        "itemType": "ldevice", 
        "pId": 18, 
        "name": "UK 06 AA 3840", 
        "open": true, 
        "id": "007060500336", 
        "icon": "/static/tree/icons/device-20.png"
    }
]

1 个答案:

答案 0 :(得分:1)

看到目录树后,相对URL必须是:

url:"/bootstrap/js/LiveMap/Ajax/JsonStringCarryingData/customer-tree-json.txt"