PDA

View Full Version : [CLOSED] pass json data in the Ajax store proxy



Sowjanya
Jul 18, 2013, 3:38 AM
Hi, I have been constantly working on the following issue , with a positivity of finding a solution, but in vain.

So here is the issue:

I am trying to find if I can pass a typical json formatted string in the store proxy request body. like I want to implement the following jquery ajax call in the ext.net store proxy


var Url = "/OperationalControlServices/Service1/data/MuseumComponentDetails";
var request = $.ajax({
url: Url,
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
data: JSON.stringify({ json: jsonString, json2: jsonString2 })
});


especially the ext.net mode of implementing the "data:" part in the above jquery is needed for me.


And the json string will be something like this -



{"json":"[{"PROJECT_ID":"2","PROJECT_NAME":"ABCD","PROJECT_DESC":"ABCD","PROJECT_STATUS_ID":"1","REMEDIATION_ID":"1","REMEDIATION_DATE":"11/20/2013 12:00:00 AM","DATE_TYPE":"Date","CONTACT_ID":"2","SID":"123456","MUSEUM_LIST":"1,6,14"}]"}

I have tried to set the root to "json" ( this json is the parameter name as you can find in the above string.), & also tried various possibilities...but no luck...:(

And finally, here is the Store proxy:


Ext.Net.Store resultStore = new Ext.Net.Store()
{
AutoLoad = autoLoad,
Proxy =
{
new AjaxProxy()
{
Json = true,

ActionMethods = { Read = Ext.Net.HttpMethod.POST, Create = Ext.Net.HttpMethod.POST},
Url = proxyUrl,

Headers = {
new Ext.Net.Parameter("Accept", "application/json"),
new Ext.Net.Parameter("Content-Type", "application/json")


},
Reader = { new Ext.Net.JsonReader() { Root = "" } },
Writer = {
new Ext.Net.JsonWriter()
{
Root="json", Encode=true // this is what I tried to do..this "json" is the parameter name in the above given json string.
}


} ,

}
}


};

Hoping to get a fix soon ! :)

Thanks a lot !
Veda

Daniil
Jul 18, 2013, 5:09 AM
Hi Veda,

Welcome to the Ext.NET forums!

I think you should set up "json" Root for the Reader.

Reader = { new Ext.Net.JsonReader() { Root = "json" } }

Does it help?

Sowjanya
Jul 18, 2013, 5:22 AM
how is it going to pass actual json data if i set this?

Daniil
Jul 18, 2013, 5:31 AM
Well, it should work with the JSON that you posted:

{"json":"[{"PROJECT_ID":"2","PROJECT_NAME":"ABCD","PROJECT_DESC":"ABCD","PROJECT_STATUS_ID":"1","REMEDIATION_ID":"1","REMEDIATION_DATE":"11/20/2013 12:00:00 AM","DATE_TYPE":"Date","CONTACT_ID":"2","SID":"123456","MUSEUM_LIST":"1,6,14"}]"}

Sowjanya
Jul 18, 2013, 5:43 AM
Well, it should work with the JSON that you posted:

{"json":"[{"PROJECT_ID":"2","PROJECT_NAME":"ABCD","PROJECT_DESC":"ABCD","PROJECT_STATUS_ID":"1","REMEDIATION_ID":"1","REMEDIATION_DATE":"11/20/2013 12:00:00 AM","DATE_TYPE":"Date","CONTACT_ID":"2","SID":"123456","MUSEUM_LIST":"1,6,14"}]"}


Actually, I am trying to do this - the web page receives the json string as a query string parameter. This json string needs to be passed to restful service.

And as per your answer, I can not set root="json" because json is just a parameter in the whole json string. Also, i dont think the Reader's root needs to be set with that value because, reader is to read the data passed from web service to the web page( as per my understanding..pls correct me if I ma wrong..)

I am trying to pass json formatted string in the ajax call to service.

for e.g,


string jsonstr = "{"json":"[{"PROJECT_ID":"2","PROJECT_NAME":"ABCD","PROJECT_DESC":"ABCD","PROJECT_STATUS_ID":"1","REMEDIATION_ID":"1","REMEDIATION_DATE":"11/20/2013 12:00:00 AM","DATE_TYPE":"Date","CONTACT_ID":"2","SID":"i340371","MUSEUM_LIST":"1,6,14"}]"}"

i want to pass jsonstr ( json is a parameter in that string.)

Thanks again !
Veda

Daniil
Jul 18, 2013, 6:33 AM
Sorry, seems I misunderstood the requirement.

Yes, a Reader is to read the data for an AjaxProxy's response.


This json string needs to be passed to restful service.

That service that you referring in the AjaxProxy's Url, right?

Url = proxyUrl

If so, you should use an AjaxProxy's ExtraParams.

<ext:AjaxProxy>
<ExtraParams>
<ext:Parameter Name="paramName" Value="getParamValueFromQueryString()" Mode="Raw" />
</ExtraParams>
</ext:AjaxProxy>

There "getParamValueFromQueryString" is supposed to be a JavaScript function returning a parameter's value.

However, it might be easier to extract the parameter from a Query string in code behind and put it to the AjaxProxy's ExtraParams in code behind as well.

Sowjanya
Jul 18, 2013, 2:11 PM
Sorry, seems I misunderstood the requirement.

Yes, a Reader is to read the data for an AjaxProxy's response.



That service that you referring in the AjaxProxy's Url, right?

Url = proxyUrl

If so, you should use an AjaxProxy's ExtraParams.

<ext:AjaxProxy>
<ExtraParams>
<ext:Parameter Name="paramName" Value="getParamValueFromQueryString()" Mode="Raw" />
</ExtraParams>
</ext:AjaxProxy>

There "getParamValueFromQueryString" is supposed to be a JavaScript function returning a parameter's value.

However, it might be easier to extract the parameter from a Query string in code behind and put it to the AjaxProxy's ExtraParams in code behind as well.


Hi Daniil,

Thanks a lot for your reply...

Yes, I am aware that extraparams works which i tried already....

I thought if there could be any way where I can pass the json string from the request directly ( so that i can capture it in web service ), without breaking this json string in the web page and passing them as extraparams..

Thanks a lot again !!!
Veda

Sowjanya
Jul 18, 2013, 2:59 PM
Hi Daniil,

Thanks a lot for your reply...

Yes, I am aware that extraparams works which i tried already....

I thought if there could be any way where I can pass the json string from the request directly ( so that i can capture it in web service ), without breaking this json string in the web page and passing them as extraparams..

Thanks a lot again !!!
Veda



Hi Daniil,

I fixed it. Just used the Extra params itself..

Appreciate your promt response to this issue.

Thanks,
Veda