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

相关内容

热门资讯

2027版外挂!湘顺外挂多功能... 2027版外挂!湘顺外挂多功能AI脚本,湘顺竟然是真的有外挂脚本1、上手简单,内置详细流程视频教学,...
2027版辅助器!星悦广西麻将... 2027版辅助器!星悦广西麻将辅助器多功能AI工具,星悦广西麻将一直有辅助器工具1)星悦广西麻将免费...
2027版外挂!家家盘锦麻将外... 2027版外挂!家家盘锦麻将外挂多功能AI工具,家家盘锦麻将真是真的是有外挂工具2027版外挂!家家...
2027版辅助!丽水跑得快辅助... 2027版辅助!丽水跑得快辅助多功能AI技巧,丽水跑得快确实有辅助技巧;亲,关键说明,丽水跑得快透视...
2027版辅助器!胡乐晋中麻将... 2027版辅助器!胡乐晋中麻将辅助器多功能AI技巧,胡乐晋中麻将果然真的是有辅助器技巧1、让任何用户...
2027版辅助!伊春麻将辅助多... 2027版辅助!伊春麻将辅助多功能AI教程,伊春麻将一贯是真的有辅助教程1、伊春麻将透视辅助软件激活...
2027版辅助器!金龙麻将辅助... 2027版辅助器!金龙麻将辅助器多功能AI软件,金龙麻将其实存在有辅助器软件1、金龙麻将模拟器是什么...
2027版开挂!熊猫麻将开挂多... 2027版开挂!熊猫麻将开挂多功能AI插件,熊猫麻将切实真的是有开挂插件所有人都在同一条线上,像星星...
2027版辅助器!雀神广东麻将... 2027版辅助器!雀神广东麻将辅助器多功能AI教程,雀神广东麻将原来真的是有辅助器教程1、雀神广东麻...
2027版透视挂!正宗闲娱娱乐... 2027版透视挂!正宗闲娱娱乐透视挂多功能AI工具,正宗闲娱娱乐竟然是真的有透视挂工具1、每一步都需...