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、很好的工具软件,可以解...
黑科技作弊器!微乐降序自建房辅... 黑科技作弊器!微乐降序自建房辅助app(作弊器),微乐郑州麻将一直是真的有透视挂教程微乐降序自建房辅...
黑科技外挂!小程序微乐辅助器下... 黑科技外挂!小程序微乐辅助器下载(外挂),微乐干瞪眼确实真的有透视挂技巧1、完成小程序微乐辅助器下载...
黑科技辅助!微乐自建房免费黑科... 黑科技辅助!微乐自建房免费黑科技下载苹果(辅助),微乐够级总是真的是有透视挂方法微乐自建房免费黑科技...
黑科技作弊器!微乐广西小程序开... 黑科技作弊器!微乐广西小程序开挂(作弊器),微乐贵阳捉鸡原来有透视挂插件1、让任何用户在无需微乐广西...
黑科技外挂!小程序微乐辅助软件... 黑科技外挂!小程序微乐辅助软件(外挂),微乐卡五星麻将果然是真的有透视挂技巧1、点击下载安装,小程序...
黑科技作弊器!微乐家乡麻将辅助... 黑科技作弊器!微乐家乡麻将辅助(作弊器),微乐盐城麻将其实真的是有透视挂技巧1、打开软件启动之后找到...
黑科技透视挂!微乐自建房辅助工... 黑科技透视挂!微乐自建房辅助工具别人怎么看(透视挂),微乐安庆麻将好像存在有透视挂教程1、这是跨平台...
黑科技开挂!微乐陕西三代自建房... 黑科技开挂!微乐陕西三代自建房挂(开挂),微乐松原麻将确实有透视挂方法1、微乐陕西三代自建房挂有没有...
黑科技辅助器!微信小程序微乐陕... 黑科技辅助器!微信小程序微乐陕西挖坑(辅助器),微乐齐齐哈尔麻将本来真的有透视挂教程暗藏猫腻,小编详...