ASP.NET:Ajax不发送字符串
创始人
2024-09-20 00:00:57
0
  1. 确保使用的是POST方法

    function sendData(strData) { $.ajax({ type: "POST", url: "MyApiUrl", data: strData, contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { console.log(response); }, error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); } }); }

  2. 设置content-type为application/json,并将data参数转换为JSON字符串

    function sendData(strData) { $.ajax({ type: "POST", url: "MyApiUrl", data: JSON.stringify(strData), contentType: "application/json; charset=utf-8", dataType: "json", success: function (response) { console.log(response); }, error: function (xhr, ajaxOptions, thrownError) { console.log(xhr.status); console.log(thrownError); } }); }

  3. 如果仍然无法发送字符串,请尝试使用XMLHttpRequest对象手动发送

    function sendData(strData) { var xhr = new XMLHttpRequest(); xhr.open('POST', 'MyApiUrl', true); xhr.setRequestHeader('Content-Type', 'application/json'); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { console.log(xhr.responseText); } }; xhr.send(strData); }

相关内容

热门资讯

我来教大家!福建天天开心辅助器... 我来教大家!福建天天开心辅助器是真的吗,天酷辅助器,详细app(有挂方针)1、超多福利:超高返利,海...
分享一款!点我休闲辅助器,大唐... 分享一款!点我休闲辅助器,大唐麻将开挂软件,详细工具(有挂攻略)1、超多福利:超高返利,海量正版游戏...
一分钟教你!微信小程序指尖四川... 一分钟教你!微信小程序指尖四川辅助器,多乐找刺激脚本,详细方法(有挂详细)1、超多福利:超高返利,海...
免费测试版!四川游戏家园通用辅... 免费测试版!四川游戏家园通用辅助,上品斗地主游戏辅助,详细app(有挂总结)该软件可以轻松地帮助玩家...
实测揭晓!798大菠萝辅助,边... 实测揭晓!798大菠萝辅助,边锋干瞪眼ios辅助,详细软件(有挂方略)边锋干瞪眼ios辅助能透视中分...
9分钟了解!多乐够级辅助软件,... 9分钟了解!多乐够级辅助软件,赣牌圈有挂吗,详细方法(有挂技巧)1、起透看视 多乐够级辅助软件辅助软...
技术分享!微信小程序辅助有哪些... 技术分享!微信小程序辅助有哪些,巴蜀长牌辅助,详细方法(有挂技术)1、微信小程序辅助有哪些公共底牌简...
一分钟快速了解!微信小程序游戏... 一分钟快速了解!微信小程序游戏破解微乐游戏,微乐小程序有脚本吗,详细工具(有挂工具)微信小程序游戏破...
玩家必看教程!小程序能不能开挂... 玩家必看教程!小程序能不能开挂,途游破解版无限钻石,详细神器(有挂教学)1、进入到途游破解版无限钻石...
六分钟了解!福建十三兵修改器,... 六分钟了解!福建十三兵修改器,随意玩免费辅助器有挂吗,详细app(有挂神器)1、进入游戏-大厅左侧-...