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

相关内容

热门资讯

一分钟带你了解!wepoker... 一分钟带你了解!wepoker游戏安装教程(辅助挂)总是真的是有挂(真的有挂辅助软件)1、首先打开辅...
揭秘关于!wejoker黑侠辅... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
科普攻略!wepoker辅助器... 科普攻略!wepoker辅助器(辅助挂)果然有挂(有挂秘籍辅助软件)1、在插件功能辅助器技巧中,中转...
一分钟了解!拱趴大菠萝机器人(... 一分钟了解!拱趴大菠萝机器人(辅助挂)其实是有挂(有挂技术辅助教程)小薇(辅助器软件下载)致您一封信...
推荐一款!聚星ai辅助工具激活... 推荐一款!聚星ai辅助工具激活码(辅助挂)其实真的有挂(有人有挂辅助器)1)辅助插件:进一步探索辅助...
最新技巧!约局吧德州透视(辅助... 最新技巧!约局吧德州透视(辅助挂)竟然真的是有挂(有挂存在辅助方法)1、全新机制【ai辅助工具激活码...
玩家必看科普!pokemmo手... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
盘点十款!hhpoker有没有... 盘点十款!hhpoker有没有外挂(辅助挂)好像存在有挂(真的有挂辅助脚本)1、超多福利:超高返利,...
重大消息!pokemmo手机脚... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很多玩家在这款游戏中打...
六分钟了解!aapoker怎么... 六分钟了解!aapoker怎么拿好牌(辅助挂)一贯是有挂(有挂透视辅助攻略)1)有没有挂:进一步探索...