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

相关内容

热门资讯

详细说明!微信微乐小程序游戏辅... 详细说明!微信微乐小程序游戏辅助脚本,微信微乐辅助透视-好像真的是有辅助方法(有挂技巧)1、上手简单...
研究成果!微乐小程序微乐辅助软... 研究成果!微乐小程序微乐辅助软件,微信小程序微乐辅助免费版-果然真的有辅助软件(有挂规律)微乐小程序...
推荐十款!微信微乐辅助免费,微... 推荐十款!微信微乐辅助免费,微乐自建房辅助工具安全吗-好像真的有辅助教程(真的有挂)1、很好的工具软...
科技通报!微信微乐小程序有挂黑... 科技通报!微信微乐小程序有挂黑科技,微信小程序微乐辅助器ios-其实真的有辅助脚本(有挂详细)1、任...
每日必看!微乐小程序微乐辅助软... 每日必看!微乐小程序微乐辅助软件,微乐陕西小程序脚本-原来有辅助软件(有挂秘籍)1、微乐小程序微乐辅...
每日必看!微乐家乡麻将辅助,下... 每日必看!微乐家乡麻将辅助,下载微乐小程序自建房透视-其实存在有辅助攻略(有挂功能)微乐家乡麻将辅助...
热点讨论!微信微乐小程序辅助器... 热点讨论!微信微乐小程序辅助器免费安装,微乐家乡小程序自建房辅助app-都是存在有辅助工具(有挂教学...
实测教程!微信小程序微乐房间怎... 实测教程!微信小程序微乐房间怎么开挂,微信自建房辅助多少钱一个月-真是存在有辅助app(有挂秘籍)1...
热点推荐!微乐家乡麻将辅助,陕... 您好,微乐家乡麻将辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩...
一分钟带你了解!微乐小程序微乐... 一分钟带你了解!微乐小程序微乐辅助软件,微乐家乡破解版-切实是真的有辅助插件(发现有挂)1、让任何用...