尝试将数据发布到db时出现404错误

时间:2016-07-04 18:31:47

标签: jquery ajax

我可以上传一个csv文件,每行只有一列。现在我想读取文件的内容并将其作为数据传递给ajax。我的代码到现在为止:

var addPortfolio = function(){
            console.log("In adding portfolio");
            var myURL = "/dashboard/btnAdd?sid=" + sid;

            var symbols = ('#uploadSymList')[0].value;
            console.log("Symbols="+symbols);
            var data={};
                data["symbols"] = symbols;
//          
            console.log("Going for an ajax call");

            var call_obj = {
                url: myURL,
                data: data,
                type: 'POST',
                return_data: true,
                success: function(data){
                    console.log("Successful request/response sent");
//                  processSymbols(data);
                },
            error : function(data) {
                    // alert("Some Error");
                    showErrorMessage("Error: Could not load to the DB.");
                }   
            };
   call_obj();
}

1 个答案:

答案 0 :(得分:0)

这不起作用,因为您不调用Ajax请求,而是创建没有任何函数的对象文字。试试这个:

$.ajax({
    url: myURL,
    data: data,
    type: 'POST',
    return_data: true,
    success: function(data){
        console.log("Successful request/response sent");
//                  processSymbols(data);
    },
error : function(data) {
        // alert("Some Error");
        showErrorMessage("Error: Could not load to the DB.");
    }   
});

或者:

$.ajax(call_obj);