PDA

View Full Version : Question about posting data to server using AJAX



Greenosity
11 Oct 2007, 7:07 AM
I need to post data to the server via Ajax and then retrieve the status (same domain). What's the most efficient, straightforward thing to use?
- Ext.Ajax.request
- Ext.data.HttpProxy.load
- ?

Most examples I've looked at are geared toward retrieving data from the server and storing that data in an Ext object such as a grid. However, I need to post items that a user selects back to the server using Ajax. All I care about after posting this data is whether the items were processed successfully or not.

I already have the data in JSON format defined on the client something like this:

var jsonPostData = [{"xmlid":22,"seqs":[1]},{"xmlid":20,"seqs":[1]},{"xmlid":30,"seqs":[1,2,3,4,5]},{"xmlid":7,"seqs":[1]}]

I can easily store it in a hidden form input instead of using a JavaScript variable or I can convert it to XML instead of JSON.

It appears that I have at least three options for posting data using Ext.Ajax.request:
1. The 'params' parameter
2. The 'form' parameter
3. The 'xmlData' parameter
If this is true, what's the most efficient, if any?

Also, I'm not clear on how to set the properties of Ext.Ajax such as 'extraParams', 'timeout', etc. since I don't see a constructor in the documentation for Ext.Ajax and it says that Ext.Ajax cannot be created directly.

devnull
11 Oct 2007, 10:04 AM
this should get you started: http://extjs.com/learn/Manual:Core:Ext.Ajax
basically you will just be sending your jsonData as a param in the ajax config.