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); }

相关内容

热门资讯

第3分钟法子!桃乐甘肃麻将辅助... 第3分钟法子!桃乐甘肃麻将辅助器,禅游指尖四川修改器,规律教程(真实有挂)-哔哩哔哩1、禅游指尖四川...
四分钟演示!三哥玩辅助器,丽水... 四分钟演示!三哥玩辅助器,丽水都莱脚本辅助,介绍教程(有挂技术)-哔哩哔哩1、每一步都需要思考,不同...
一分钟攻略!兴动互娱软件辅助下... 一分钟攻略!兴动互娱软件辅助下载,禅游游戏辅助脚本,可靠教程(有挂总结)-哔哩哔哩1、兴动互娱软件辅...
两分钟方案!广东雀神挂件定制,... 两分钟方案!广东雀神挂件定制,微信新九游辅助,第三方教程(有挂细节)-哔哩哔哩1、广东雀神挂件定制透...
1分钟课程!微乐江西小程序辅助... 1分钟课程!微乐江西小程序辅助器免费,赣牌圈挂安装图解,细节方法(有挂透视)-哔哩哔哩1、很好的工具...
第2分钟项目!人人燕赵挂,潮汕... 第2分钟项目!人人燕赵挂,潮汕掌手娱辅助器,软件教程(有挂方式)-哔哩哔哩1)潮汕掌手娱辅助器辅助挂...
第9分钟攻略!新道游开挂辅助透... 第9分钟攻略!新道游开挂辅助透视,阿拉游戏中心辅助,透明挂教程(揭秘有挂)-哔哩哔哩1、新道游开挂辅...
8分钟讲义!中至赣牌圈科技,兴... 8分钟讲义!中至赣牌圈科技,兴动互娱脚本,必胜教程(证实有挂)-哔哩哔哩1、打开软件启动之后找到中间...
一分钟要领!福建兄弟水挂,川友... 一分钟要领!福建兄弟水挂,川友汇辅助软件,总结教程(有挂实锤)-哔哩哔哩1、这是跨平台的川友汇辅助软...
7分钟项目!九九山城插件程序,... 7分钟项目!九九山城插件程序,拱趴游戏诀窍,科技教程(有挂分享)-哔哩哔哩1、九九山城插件程序透视辅...