4

I've used this method in .NET to pass data back and forth between client and server using JSON objects (both ways). I really liked the method and am looking to do something similar with web2py. Web2py supports returning json objects and supports jsonrpc. I haven't however been able to make it parse a JSON object. My client call looks like this:

var testObject = {};
testObject.value1 = "value1value!";
testObject.value2 = "value2value!";

var DTO = { 'testObject' : testObject };
var data = $.toJSON(DTO);    //Using the toJSON plugin by Mark Gibson

  $.ajax({
    type: 'POST',
    url: '/MyWeb2PyApp/MyController/jsontest.json',
    contentType: "application/json; charset=utf-8", 
    data: data,
    dataType: 'json',
success:  function(data){  alert('yay'); }
});

I've tried a bunch of stuff in my jsontest action and nothing works.

Has anyone been able to accomplish something similar?

Much appreciated.

1 Answer 1

7

there are multiple ways. In your case the simplest thing to do is

def jsontest():
   import gluon.contrib.simplejson
   data = gluon.contrib.simplejson.loads(request.body.read())
   return dict()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.