我试图将一个JSON对象发布到asp.net webservice.
我的json看起来像这样:
var markers = { "markers": [
{ "position": "128.3657142857143", "markerPosition": "7" },
{ "position": "235.1944023323615", "markerPosition": "19" },
{ "position": "42.5978231292517", "markerPosition": "-3" }
]};
Run Code Online (Sandbox Code Playgroud)
我使用json2.js来串行我的json对象.
我正在使用jquery将其发布到我的webservice.
$.ajax({
type: "POST",
url: "/webservices/PodcastService.asmx/CreateMarkers",
data: markers,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
"无效的JSON原语:
我发现了一堆与此相关的帖子,这似乎是一个非常常见的问题,但我没有尝试解决这个问题.
当firebug发布到服务器的内容时,它看起来像这样:
标记%5B0%5D%5Bposition%5D = 128.3657142857143&标记%5B0%5D%5BmarkerPosition%5D = 7&标记%5B1%5D%5Bposition%5D = 235.1944023323615&标记%5B1%5D%5BmarkerPosition%5D = 19&标记%5B2%5D%5Bposition% 5D = 42.5978231292517&标记%5B2%5D%5BmarkerPosition%5D = -3
我正在调用的webservice函数是:
[WebMethod]
public string CreateMarkers(string markerArray)
{
return "received markers";
}
Run Code Online (Sandbox Code Playgroud) 我有一份注册表,我正在使用$.ajax它提交.
这是我的AJAX请求:
$(document).ready(function() {
$("form#regist").submit(function() {
var str = $("#regist").serialize();
$.ajax({
type: 'POST',
url: 'submit1.php',
data: $("#regist").serialize(),
dataType: 'json',
success: function() {
$("#loading").append("<h2>you are here</h2>");
}
});
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
在我的submit1.php文件中,我检查数据库中是否存在字段电子邮件地址和用户名.如果在没有页面刷新的情况下存在这些值,我希望显示错误消息.
如何将此添加到我的AJAX请求的成功回调中?
我有一个ASP.Net页面的以下jQuery AJAX调用.
$.ajax({
async: true,
type: "POST",
url: "DocSummaryDataAsync.aspx", //"DocSummary.aspx/GetSummaryByProgramCount",
contentType: "application/json; charset=utf-8",
data: kendo.stringify({ vendorId: supplierId, businessUnit: busUnit, productSegmentId: prodSegmentId, programId: progId, productManagerId: prodManagerId, companyIds: compIds, expired: exp.toString(), requestType: 'TotalCount' }),
success: function (msg) {
// alert('in success of getcount');
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
// alert('in failure of getcount');
}
});
Run Code Online (Sandbox Code Playgroud)
当我尝试从Request对象中检索已发布的数据时,它不会显示出来.我的aspx页面代码如下.我将每个以Json格式发布的数据发送到页面,但它不会显示在页面的代码隐藏中.在我缺少的jQuery ajax调用中是否有一些额外的设置?
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
string requestType = Request.Params["requestType"];
//populate variables from posted data
string vendorId = …Run Code Online (Sandbox Code Playgroud) 我有以下angularjs代码发送http帖子到webmethod,但我得到以下错误没有更多的信息.有人可以帮忙吗?如果我不向webmethod发送任何数据并且只从中获取数据,它就可以了!
无法加载资源:服务器响应状态为500(内部服务器错误)angular.js:11442 POST http:// localhost:54461/GetData.aspx/getData 500(内部服务器错误)
使用Javascript:
var request = "{'name':'" + "Nariman" + "'age':'" + 12 + "'}";
$scope.retData = {};
var config = {
headers: {
'Content-Type': '"application/json; charset=utf-8";',
'dataType': '"json"'
}
}
$scope.retData.getResult = function (item, event) {
$http.post('GetData.aspx/getData', request, config)
.success(function (data, status, headers, config) {
$scope.retData.result = data.d;
})
.error(function (data, status, headers, config) {
$scope.status = status;
});
}
Run Code Online (Sandbox Code Playgroud)
ASPX webmethod(C#):
public static string getData(string name, int age)
{
string.Format("Name: {0}{2}Age: {1}", name, age, …Run Code Online (Sandbox Code Playgroud) 我正在研究AJAX。我创建如下的发帖请求:
$.ajax({
'url':'http://localhost/api/create/',
'method':'POST',
'dataType': 'json',
'contentType': 'application/json',
'data':{
"refId":585,
"phone":"0674444444"
},
'success': getHandlingStatus
});
Run Code Online (Sandbox Code Playgroud)
执行我的请求时,数据将作为参数传递到我的请求有效负载中,而不是作为JSON数据传递。这是我的请求有效负载:
refId=585&phone=0674444444
Run Code Online (Sandbox Code Playgroud)
我想以json格式发送数据,例如:
{
"refId":"585",
"phone:"0674444444"
}
Run Code Online (Sandbox Code Playgroud)
我想念什么?
jquery ×4
ajax ×3
asp.net ×2
javascript ×2
post ×2
angularjs ×1
c# ×1
content-type ×1
json ×1
web-services ×1
webmethod ×1