![](/img/trans.png)
[英]Returning a string array from JsonResult and using it in a JavaScript
[英]How to send a get request to a jsonresult with a string parameter using JavaScript Fetch?
我試圖從服務器獲取api 。 即時通訊使用mvc jsonresult來創建api。 jsonresult將字符串id作為參數。 那么如何使用fetch將id從客戶端傳遞到服務器?
我嘗試發送id就像一個int或任何數值,但它不起作用! 我也嘗試將其作為查詢字符串傳遞,但它也沒有用!
這是我第一次嘗試傳遞id:
fetch(`/controller/jsonresult/${id}`)
我還嘗試將其作為查詢字符串獲取
fetch(`/controller/jsonresult/get?id=${id}`)
我期望字符串將到達jsonresult,所以我可以根據id獲取信息,但它總是收到null
我不久前想出來但是忘了在這里發帖抱歉!
我在我的控制器中使用[Authorize]數據注釋,這就是為什么我無法從控制器中獲取jsonresult!
它運作得很好,
fetch(`/controller/jsonresult/${id}`)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.