سؤال

I have been using the JayRock framework with ASP.NET to return JSON being consume via javascript. Everything has worked fine until I changed the $.ajax call from a GET to a 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:

    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.

هل كانت مفيدة؟

المحلول

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

نصائح أخرى

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top