Topic
  • No replies
SystemAdmin
SystemAdmin
570 Posts

Pinned topic Worklight JSON Post Request

‏2012-05-26T08:58:07Z |
Hello.
How I can dynamically generate json post request?
I do like this:

Generating json request

var JSONRequest = 
{
};   
// get data from form  jq(
'#new_form input').each(function(index) 
{ var nameInput = jq(

this).attr(
"name"); var valInput = jq(

this).val(); JSONRequest[nameInput] = valInput; 
});   

return JSONRequest;


Call adapter method

function serviceSubmitRequestMethod(JSONRequest) 
{   var invocationData = 
{ adapter : 
'AdapterName', procedure : 
'submitRequest', parameters : [JSONRequest] 
}; WL.Client.invokeProcedure(invocationData,
{ onSuccess : function(data) 
{
} onFailure : function(data) 
{
} 
}); 
}


Adapter function

function submitRequest(JSONRequest) 
{ var postRequestParams = 
{ method :  
'post', path : 
'api/test/requests.json', returnedContentType : 
'json', parameters: JSONRequest 
}; 

return WL.Server.invokeHttp(postRequestParams); 
}


statusCode is 200 but my post request return error response.
What I do wrong?