0

我一直在使用带有 ASP.NET 的 JayRock 框架来返回通过 javascript 使用的 JSON。一切正常,直到我将 $.ajax 调用从 GET 更改为 POST。在进行该更改后,我现在收到此错误。

{"id":null,"error":{"name":"JSONRPCError","message":"Missing value.","errors":[{"name":"JsonException","message":"Missing value."}]}}

这是我的javascript:

    var tmp = '{ "assID": 52 }';
    var tmpObj = $.parseJSON(tmp);


$.ajax
({
    type: "POST",
    url: '/jsonC.ashx/tester',
    dataType: 'json',
    data: tmpObj,
    async: true,
    contentType: 'application/json',
   success: function (result) {
        console.log(JSON.stringify(result));
    }
})

有人有想法么?提前致谢。

4

2 回答 2

0

您需要将参数添加为配置值中的数据...

$.ajax
({
    type: "POST",
    url: '/jsonC.ashx/tester',
    dataType: 'json',
    data: {id: some_value, other_var: 'some string'}
    async: true,
    contentType: 'application/json',
   success: function (result) {
        console.log(JSON.stringify(result));
    }
})

只需用您的实际值替换数据的内容。就目前而言,您正在发布到页面但不发送任何帖子变量。

于 2011-11-04T21:05:24.853 回答
0

这是应该做什么的定义:

var dataString = '{ "assID": 52 }'; 
var postData = $.parseJSON(dataString);
var response;
$.ajax({
  type: 'POST',
  url: '/jsonC.ashx/tester',
  contentType: 'application/json',
  data: JSON.stringify(postData),
  dataType: 'json',
  success: function(data) {
      //do something for success if you want. If your response is JSON:
      response = $.parseJSON(data)
  },
  error: function(data) {
      //do somtething for error if you want. If your response is JSON:
      response = $.parseJSON(data)
  }
});
于 2011-11-04T21:09:11.497 回答