-
14 Jan 2011 3:20 AM #1
I'm confused about GET and POST in Sencha-touch
I'm confused about GET and POST in Sencha-touch
I have a lot of PHP serverscripts that produce JSON from a DB to fill a store. These scripts looks for POST and GET parameters. If a POST parameter is available the script send normal JSON. If only GET parameter is received the script sends callback(.....) javascript. Because in ExtJS HttpProxy is default send with type: 'POST' and HttpScriptTagProxy requests are send with default type: 'GET'.
I expected Sencha-touch behave like ExtJS. No matter what I try to make request to get storedata Sencha-touch always send a GET request with URL-params. Another issue is that Sencha-touch expects a JSON message back and not a callback javascript.
As a workaround I sent an extra param mobile: true in requests. My PHP scripts now looks for this ??GET param mobile and act like a request width send with POST and send back a JSON message.
Is it possible to make requests that use type: POST???
-
14 Jan 2011 8:24 AM #2
Hi, sure you can make POST requests.
Try to write your request like this:
Hope this helps.PHP Code:Ext.Ajax.request({
url: 'your_url'
method: 'post',
params: {
my_param: 'my_value'
},
success: function(response, opts) {
//Do what you want
}
})
Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
15 Jan 2011 3:12 AM #3
Hi Andrea,
I know. I used that always in ExtJS. Works perfect. But if you try to define a proxy like following code, Sencha-touch ignores the parameter and always sends a GET Request with values added in the URL.
Here is a copy of the request send by code above:Code:var servincidentStore = new Ext.data.Store({ model: 'Incident', storeId: 'incident', proxy: { type: 'ajax', url: '/generator-grid/BackendGrid/incidentGridBackend.php', method: 'POST', extraParams: { mobile: true, start: 0, limit: 9999, userProfielId: profielid, task: 'LISTING', xvelden: ', incident.PersoonId ', sort: 'incident.Incident', dir: 'ASC' }, reader: { type: 'json', root: 'results' } } });
Code:Verzoek-URL:http://localhost/generator-grid/BackendGrid/incidentGridBackend.php?_dc=1295089977116&mobile=true&start=0&limit=25&userProfielId=791&task=LISTING&xvelden=%2C%20incident.PersoonId%20&sort=incident.Incident&dir=ASC Verzoekmethode:GET Statuscode:200 OK Vraagkopteksten
-
15 Jan 2011 3:26 AM #4
Hi,
Sencha Touch it's a little bit different from Ext.
If you have to get data from a Store using Post, you have to set the actionMethods config as follow instead of method.
Hope this helps.PHP Code:var servincidentStore = new Ext.data.Store({
model: 'Incident',
storeId: 'incident',
proxy: {
type: 'ajax',
url: '/generator-grid/BackendGrid/incidentGridBackend.php',
actionMethods: {
read: 'POST'
},
extraParams: {
mobile: true,
start: 0,
limit: 9999,
userProfielId: profielid,
task: 'LISTING',
xvelden: ', incident.PersoonId ',
sort: 'incident.Incident',
dir: 'ASC'
},
reader: {
type: 'json',
root: 'results'
}
}
});
Sencha Inc
Andrea Cammarata, Solutions Engineer
CEO at SIMACS
@AndreaCammarata
www.andreacammarata.com
github: https://github.com/AndreaCammarata
-
19 Jul 2011 4:44 AM #5
We're trying the same way but getting the following error, Stuck in this
, using Sencha touch
If you call this using Chrome's REST Console plugin it returns correct response, but May be in case of POST request from STORE it adds some header?
Can anybody please help here...
Following is the code
-----------------------CODE-----------------
var ProductListStore = new Ext.data.Store({
model: 'ProductListRoot',
proxy: {
type: 'ajax',
actionMethods: {
read: 'POST'
},
url: urlIdentifier + instanceId + implementationId + productListSearchURL,
reader:{
type: 'json',
root: 'contents'
}
},
autoLoad:true
});
---------------------------------------------------
and Following is the error
Following is the error return if we inspect in the browser's console.
----------------------------------ERROR---------------------------
<html><head><title>Apache Tomcat\/5.5.23 - Error report<\/title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--><\/style> <\/head><body><h1>HTTP Status 404 - Invalid numeric value: Missing integer part (next char '-' (code 45))\n at [Source: ------------------------------be6f1d32f73c\r\nContent-Disposition: form-data; name="limit"\r\n\r\n25\r\n------------------------------be6f1d32f73c--\r\n; line: 1, column: 3]<\/h1><HR size=\"1\" noshade=\"noshade\"><p><b>type<\/b> Status report<\/p><p><b>message<\/b> <u>Invalid numeric value: Missing integer part (next char '-' (code 45))\n at [Source: ------------------------------be6f1d32f73c\r\nContent-Disposition: form-data; name="limit"\r\n\r\n25\r\n------------------------------be6f1d32f73c--\r\n; line: 1, column: 3]<\/u><\/p><p><b>description<\/b> <u>The requested resource (Invalid numeric value: Missing integer part (next char '-' (code 45))\n at [Source: ------------------------------be6f1d32f73c\r\nContent-Disposition: form-data; name="limit"\r\n\r\n25\r\n------------------------------be6f1d32f73c--\r\n; line: 1, column: 3]) is not available.<\/u><\/p><HR size=\"1\" noshade=\"noshade\"><h3>Apache Tomcat\/5.5.23<\/h3><\/body><\/html>
------------------------------- Tahir Rauf
Similar Threads
-
Is Sencha working on native wrappers to package Sencha Touch apps for app stores?
By olin in forum Sencha Touch 1.x: DiscussionReplies: 10Last Post: 20 Jan 2012, 10:10 AM -
Sencha Touch on iPhone v1 / iPod touch v1 ?
By palnap in forum Sencha Touch 1.x: DiscussionReplies: 4Last Post: 28 Oct 2010, 5:30 PM -
you should update the post title to "Sencha Touch Releases & Notes (0.98)"
By sandor in forum Sencha Touch 1.x: DiscussionReplies: 0Last Post: 28 Oct 2010, 11:25 AM -
[CLOSED-267] Sencha Touch API docs lacking some "Sencha Platform" content?
By charris in forum Sencha Touch 1.x: BugsReplies: 2Last Post: 9 Sep 2010, 10:24 AM


Reply With Quote