英文:
Not able to call API from jquery
问题
以下是您的JavaScript代码的翻译:
var Id = 32456;
$.ajax({
type: "POST",
url: RetrieveValue('href') + '/API/Delete',
headers: {
'Authorization': 'Bearer ' + RetrieveValue("Token"),
},
data: '{"Id":' + Id+ '}',
async: true,
cache: false,
dataType: "json",
contentType: "application/json",
success: function (response) {
},
error: function (error) {
}
});
以下是您的API代码的翻译:
[HttpPost("Delete/")]
public async Task<ActionResult> Delete(long Id)
{
}
如果您传递了值,但ID仍然为0,可能需要检查一下传递的值是否正确,并确保在请求正文中以JSON格式传递了正确的ID值。
英文:
My JS code:
var Id = 32456;
$.ajax({
type: "POST",
url: RetrieveValue('href') + '/API/Delete',
headers: {
'Authorization': 'Bearer ' + RetrieveValue("Token"),
},
data: '{"Id":' + Id+ '}',
async: true,
cache: false,
dataType: "json",
contentType: "application/json",
success: function (response) {
},
error: function (error) {
}
});
My API code:
[HttpPost("Delete/")]
public async Task<ActionResult> Delete(long Id)
{
}
I am getting ID = 0, even though I have passed value.
Thanks for your help in advance.
答案1
得分: -1
将id设置为查询参数:
url: RetriveValue('href') + '/API/Delete?Id=' + Id
英文:
Set id as query parameter:
url: RetriveValue('href') + '/API/Delete?Id=' + Id
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论