PDA

View Full Version : Ajax Requests from Data Writers



mcamer
20 Jul 2010, 2:12 PM
Hey Guys, I am dealing with a special kind of RESful service ... what I've been noticing is you can dig in most of the services' data with '/'s ... So for example in order to reach customer with ID 10 I would hit
http://www.domain.com/Customer/10

Which what pretty much the DataWriters support in ExtJS "to my knowledge"

The service I'm consuming and writing back to deal with it a bit differently, so instead of /10 it will be (10)
which means the upper example will be something like

http://www.domain.com/Customer(10)

Now I can reach that by using the Ajax requests no problems, but when I try to use the DataWriters in order to bind it with the grid and do magical updates, it tends to follow the '/' way, would you be able to pin point me on where can I change this behaviour?

Thank you in advance for the help :)

Regards,
Amer

Aero
20 Jul 2010, 4:25 PM
Hi Amer,

I am new to ExtJs so i just thinking out loud here.I didn't even know this was the case,so i am intrested in a solution as well. But if i understand you correctly you want to take advantages of the CRUD api using the writer. But the url can not be accepted with that (10) form.

Isn't it possible to catch the save,update etc actions in a before event on the store to either (redefine the url for the CRUD..probably not allowed re-direct to your url). If using DirectProxy this seems possible to inlcude a function instead of a given url as a second param which means a AJAX request could been made there. But if you just do a AJAX request in the beforeEvent,isn't possible to get the records (dirty fields for instance) and send them along with this request.

I dont know,mabey you can solve it server-side by having dummy CRUD urls and send some params and include the correct urlpaths from there?

Cheers!

mcamer
20 Jul 2010, 5:18 PM
Thank you for the reply Aero.
That is correct, I do want to use the CRUD's API, but the API expects Customer(10), where the standard Ajax requests send it as Customer/10.

Now I didn't think of overriding the events of save and update, that could be a solution. I can probably create the requests I want using the URL format the API expects. But I have a strong feeling that there's a way to override the actual Ajax request method itself.
So instead of sending Customer/10, it will send Customer(10) on the Ajax Request level. This way I would actually avoid extending the stores or the GridPanels.

But at least I can think of this as a back-up plan. So thank you again :)

Regards,
Amer

Aero
20 Jul 2010, 5:57 PM
Amer,

Yeah,there is probably a method for overridning the actual AJAX/api request so you can use (10). I am sure Animal,Garcia or Conor know how to do it.:)

Still,if it is possible to do any ajax request in any after-event, the challenge is to get the callback/records that the api crud so nicley fix for us without looping with the gridselectionmodel/getModifedRecord etc.

if you just had api url that returned {success : true} wouldn't it be possible to catch the callback json and send it along with your AJAX.

Well,good luck any way i will watch this thread how it can be solved :-?

mcamer
21 Jul 2010, 9:48 AM
Ok, so I was able to solve this issue by a simple overriding of the HTTPProxy's method buildUrl.
Within the lines of that function, there's the part where it actually builds the URL based on the record.id.
So the part where it says

url += '/' + record.id;
I changed it to

url += '(' + record.id + ')';

Pretty simple, but the pain in the neck part was to actually spot it!