简体   繁体   English

将类型切换为POST而不是GET后,JSON调用不起作用

[英]JSON calls not working after switching type to POST instead of GET

I have been using the JayRock framework with ASP.NET to return JSON being consume via javascript. 我一直在使用JayRock框架和ASP.NET来返回通过JavaScript使用的JSON。 Everything has worked fine until I changed the $.ajax call from a GET to a POST. 在将$ .ajax调用从GET更改为POST之前,一切工作正常。 Upon that change I now receive this error. 进行更改后,我现在收到此错误。

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

Here is my javascript: 这是我的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));
    }
})

Anyone have any ideas? 有人有想法么? Thanks in advance. 提前致谢。

You need to add your parameters as data in the config values... 您需要将参数作为数据添加到配置值中...

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

just replace the contents of data with your actual values. 只需将数据内容替换为您的实际值即可。 As it stands you are posting to a page but sending no post vars. 就目前而言,您正在发布到页面,但不发送任何发布变量。

Here is the definition of what should do: 这是应该做什么的定义:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM