PDA

View Full Version : Using Ext.Ajax.Request to send jsonData is not working as expected



amal.arindam
17 Nov 2010, 8:09 AM
Hi,
I am using Ext.Ajax.Request to fire an ajax request with json data. I am creating an array of jsonObjects and passing it but the objects is not getting populated. If i pass the entities as params it works. I cannot use params as an option because i need to send complex objects to the server and it might be a list of objects. Below is the code :
Please let me know if i am missing something here and let me know the possible solution. I am using Struts 2.0.14. I tried intercepting the request and look through it by TCP/IP monitor and fiddler. The request object does not have the json object i sent.
var singleJsonObj = {
'jsonBean.startDate' : arrayOfEventsWithSameIds[0].get('StartDate'),
'jsonBean.endDate' : arrayOfEventsWithSameIds[0].get('EndDate')
}

//Ajax Call started
Ext.Ajax.request({
url: 'http://localhost:8081/StrutsPro/populateJson.action',
method:'POST',
jsonData : Ext.encode(singleJsonObj) ,
scope:this,
success: function ( result, request ) {
Ext.Msg.alert("Call Succeeded");
//var jsonData = Ext.decode(result.responseText);
//var resultMessage = jsonData.data.result;
//doSomethingWithResult(resultMessage, Success);
},
failure: function ( result, request ) {
Ext.Msg.alert("Call failed");
//var jsonData = Ext.decode(result.responseText);
//var resultMessage = jsonData.data.result;
// doSomethingWithResult(resultMessage, Error);
}
});

matt617
17 Nov 2010, 11:46 AM
is that URL the same place hte page is coming from? do you think you are breaking any cross domain ajax rules here? I do not see a script tag proxy so you need ot be requesting ot the same domain as the page lives. Also are you using firefox? What does firebug have to say on the net tab?

Screamy
17 Nov 2010, 12:19 PM
Just to double-check, you have the JSON interceptor configured for Struts 2, yes?

Also, do yourself a HUGE favor and dump Struts 2 for Spring MVC. You'll be glad you did...

:]

amal.arindam
17 Nov 2010, 3:14 PM
is that URL the same place hte page is coming from? do you think you are breaking any cross domain ajax rules here? I do not see a script tag proxy so you need ot be requesting ot the same domain as the page lives. Also are you using firefox? What does firebug have to say on the net tab?

Hi Matt,
I have used the full url, because i was executing the script from web browser.(HTML file having the script). I am hitting a different application which is deployed on the server.I did not understand the "script tag proxy" stuff. Have I not used current syntax for making an Ext Ajax call? This is what i found in the API.
The call is successful when i used params instead of jsonData and i see parameters populated in my action class. I used both IE and firefox. The Net tab of firebug is not showing me any request body. Also, i checked the request on TCP/IP monitor and could not see a request body. I will check with my JSON interceptor in Struts. I am using Strust 2.0.14. I am using json pluggin 0.32 for compatibilty. If you guys have any examples which displays an end to end implementation , please share it. That would be helpful.

amal.arindam
17 Nov 2010, 11:27 PM
Hi,
The issue is resolved. There was an issue with the interceptor. I created a custom interceptor and was able to intercept the Json request. :)

matt617
18 Nov 2010, 6:37 AM
great! glad to hear it worked out. may i ask what was wrong with the other interceptor? I feel like since an encodedJSON objectis just a string it should have been able to handle the string just not known what to do with it...

amal.arindam
18 Nov 2010, 6:43 AM
great! glad to hear it worked out. may i ask what was wrong with the other interceptor? I feel like since an encodedJSON objectis just a string it should have been able to handle the string just not known what to do with it...

There was an issue in my configuration. I corrected it. Also, i tried creating my own interceptor and intercepted the HttpRequest , the same work what a standard interceptor would do, even that worked. :)

akandach
25 Apr 2012, 10:02 AM
Can you guys post some example sencha + structs