0

我在 Durundal 的 JS 文件中有以下 ajax cal,

var dataJSON ={ID : "jo"};
self.js = $.ajax({
    type: "POST",
    dataType: text,
    url: "http://localhost:53081/api/File",
    data: JSON.stringify(dataJSON),

    error: function (xhr, status, error) {
        alert(error);
    },
    success: function (json) {
        alert("Data Returned: " + JSON.stringify(json));
    }
});

我的 REST api 是

[HttpPost]
public string upload(string ID)
{



    string givenId = ID;
    return givenId;

}

但是当我调用 thsi 方法时,我只是收到错误警报。什么地方出了错

更新

我已经更新了我的代码,但现在我收到 Not found 错误

4

2 回答 2

0

将字符串更改为文本:

self.js = $.ajax({
    type: "POST",
    dataType: **Text**,
    url: "url",
    data: JSON.stringify(dataJSON),

    error: function (xhr, status, error) {
        alert(status);
    },
    success: function (json) {
        alert("Data Returned: " + JSON.stringify(json));
    }
});

单击此处获取数据类型列表和表示形式。

于 2013-09-18T13:16:29.140 回答
0

您可能需要将方法的名称更改为PostFile. 我在没有正确命名约定的情况下让它工作时遇到了问题,即使我[HttpPost]在方法的开头有这个属性。

另外:尝试将您的 dataType 更改为“json”并添加内容类型:

            dataType: "json",
            contentType: "application/json"
于 2013-09-18T22:15:37.100 回答