-
12 Apr 2009 8:39 AM #1
Jelp in Air with php
Jelp in Air with php
Hi
I am really struck up in this.. i am new to air.
This is my code
Code:var PresidentsDataStore; var PresidentsColumnModel; var PresidentListingEditorGrid; var PresidentListingWindow; Ext.onReady(function() { Ext.QuickTips.init(); function saveThePresident(oGrid_event) { Ext.Ajax.request({ waitMsg: 'Please wait...', url: '1.php', params: { task: "UPDATEPRES", IDpresident: oGrid_event.record.data.IDpresident, FirstName: oGrid_event.record.data.FirstName, LastName: oGrid_event.record.data.LastName, PartyName: oGrid_event.record.data.PartyName, TookOffice: oGrid_event.record.data.TookOffice.format('Y-m-d'), LeftOffice: oGrid_event.record.data.LeftOffice.format('Y-m-d'), Income: oGrid_event.record.data.Income }, success: function(response) { var result = eval(response.responseText); switch (result) { case 1: PresidentsDataStore.commitChanges(); PresidentsDataStore.reload(); break; default: Ext.MessageBox.alert('Uh uh...', 'We couldn\'t save him...'); break; } }, failure: function(response) { var result = response.responseText; Ext.MessageBox.alert('error', 'could not connect to the database. retry later'); } }); } PresidentsDataStore = new Ext.data.Store({ id: 'PresidentsDataStore', proxy: new Ext.data.HttpProxy({ url: '1.php', method: 'POST' }), baseParams: { task: "LISTING" }, // this parameter is passed for any HTTP request reader: new Ext.data.JsonReader({ root: 'results', totalProperty: 'total', id: 'id' }, [ { name: 'IDpresident', type: 'int', mapping: 'IDpresident' }, { name: 'FirstName', type: 'string', mapping: 'firstname' }, { name: 'LastName', type: 'string', mapping: 'lastname' }, { name: 'IDparty', type: 'int', mapping: 'IDparty' }, { name: 'PartyName', type: 'string', mapping: 'name' }, { name: 'TookOffice', type: 'date', mapping: 'tookoffice' }, { name: 'LeftOffice', type: 'date', mapping: 'leftoffice' }, { name: 'Income', type: 'float', mapping: 'income' } ]), sortInfo: { field: 'IDpresident', direction: "ASC" } }); PresidentsColumnModel = new Ext.grid.ColumnModel( [{ header: '#', readOnly: true, dataIndex: 'IDpresident', width: 40, hidden: false }, { header: 'First Name', dataIndex: 'FirstName', width: 60, editor: new Ext.form.TextField({ allowBlank: false, maxLength: 20, maskRe: /([a-zA-Z0-9\s]+)$/ }) }, { header: 'Last Name', dataIndex: 'LastName', width: 80, editor: new Ext.form.TextField({ allowBlank: false, maxLength: 20, maskRe: /([a-zA-Z0-9\s]+)$/ }) }, { header: 'ID party', readOnly: true, dataIndex: 'IDparty', width: 50, hidden: true }, { header: 'Party', dataIndex: 'PartyName', width: 150, editor: new Ext.form.ComboBox({ typeAhead: true, triggerAction: 'all', store: new Ext.data.SimpleStore({ fields: ['partyValue', 'partyName'], data: [['1', 'No Party'], ['2', 'Federalist'], ['3', 'Democratic-Republican'], ['4', 'Democratic'], ['5', 'Whig'], ['6', 'Republican']] }), mode: 'local', displayField: 'partyName', valueField: 'partyValue', lazyRender: true, listClass: 'x-combo-list-small' }) }, { header: 'Took Office', dataIndex: 'TookOffice', width: 80, renderer: Ext.util.Format.dateRenderer('m/d/Y'), editor: new Ext.form.DateField({ format: 'm/d/Y' }), hidden: false }, { header: 'Left Office', dataIndex: 'LeftOffice', width: 80, renderer: Ext.util.Format.dateRenderer('m/d/Y'), editor: new Ext.form.DateField({ format: 'm/d/Y' }), hidden: false }, { header: "Income", dataIndex: 'Income', width: 100, renderer: function(v) { return '$ ' + v; }, editor: new Ext.form.NumberField({ allowBlank: false, allowDecimals: true, allowNegative: false, blankText: '0', maxLength: 11 }) }] ); PresidentsColumnModel.defaultSortable = true; PresidentListingEditorGrid = new Ext.grid.EditorGridPanel({ id: 'PresidentListingEditorGrid', store: PresidentsDataStore, cm: PresidentsColumnModel, enableColLock: false, clicksToEdit: 1, selModel: new Ext.grid.RowSelectionModel({ singleSelect: false }) }); PresidentListingWindow = new Ext.Window({ id: 'PresidentListingWindow', title: 'The Presidents of the USA', closable: true, width: 700, height: 350, plain: true, layout: 'fit', items: PresidentListingEditorGrid }); PresidentsDataStore.load(); PresidentListingWindow.show(); PresidentListingEditorGrid.on('afteredit', saveThePresident); });Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title>Untitled Document</title> <link rel="stylesheet" type="text/css" href="ext-2.0/resources/css/ext-all.css" /> <link rel="stylesheet" type="text/css" href="ext-air/resources/ext-air.css" /> <script type="text/javascript" src="adobe/AIRAliases.js"></script> <script type="text/javascript" src="ext-2.0/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="ext-2.0/ext-all.js"></script> <script type="text/javascript" src="ext-air/ext-air.js"></script> <script type="text/javascript" src="1.js"></script> <script type="text/javascript" src="js/ext-config.js"></script> </head> <body> </body> </html> But i dont get any data in the grid what seems to be the problem.. If i run this code normally in IE i get the data in the grid... Is there anything i have to do in Aptana to access XMLhttprequest config
-
12 Apr 2009 9:41 AM #2
first off, try adding AIRIntrospector.js to your header, after your adobe/AIRAliases.js call. Introspector is simlar (but not as good! :P) as firebug and is activated by pressing F12 when you are running your application. Introspector will allow you to check what the XHR request is, and what the server returned. If your grid is not populating, it could be because the server is not sending any or malformed JSON data
however, i think the issue may be this line
try changing it toCode:var result = eval(response.responseText);
but then again, it all depends on what your server is returning. =)Code:var result = eval('('+response.responseText+')');
-
12 Apr 2009 4:33 PM #3
I added AIRIntrospector.js and while running i pressed F12 i get this error
about:blank:6265 HTML ERROR: Unmatched </head> encountered. Ignoring tag.
about:blank:6267 HTML ERROR: Extra <body> encountered. Migrating attributes back to the original <body> element and ignoring the tag.
-
12 Apr 2009 4:53 PM #4
[quote=king1231986;315648]I added AIRIntrospector.js and while running i pressed F12
I got no reponse from the server. I could find there is no post from air.
I ran my application in firefox and not in Air. I get the response.
please help me. I am not able to move forward.
I am using WAMP server 2.0g
-
12 Apr 2009 4:54 PM #5
Hmm.... possible its returning an HTML file, which is why its closing/opening your <head> and <body> tags?
for your sucess function, change it to
let me know what returnsCode:function (response) { alert(response.responseText); }
-
12 Apr 2009 6:54 PM #6
oh you know, i didnt see your 3rd post there above mine till just now :P
did you change the URL from 1.php to the full url (www.example.com/1.php) ?
-
13 Apr 2009 5:36 PM #7
hi i gave the full link no good luck
and i also tried this but this also doest seems to work...
Code:<html> <head> <title>Application Sandbox sample</title> <link href="sample.css" rel="stylesheet" type="text/css"/> <link rel="stylesheet" type="text/css" href="lib/ext/resources/css/ext-all.css" /> <link rel="stylesheet" type="text/css" href="lib/air/resources/ext-air.css" /> <script type="text/javascript" src="lib/air/AIRAliases.js"></script> <script type="text/javascript" src="lib/air/AIRIntrospector.js"></script> <script type="text/javascript" src="lib/ext/adapter/ext/ext-base.js"></script> <script type="text/javascript" src="lib/ext/ext-all.js"></script> <script type="text/javascript" src="lib/ext/air/ext-air.js"></script> <script type="text/javascript"> // loads the content of a remote URL function doRequest() { alert(); var req = new XMLHttpRequest(); req.onreadystatechange = function() { if (req.readyState == 4) { var str = req.responseText; if (str.length > 400) { str = str.substring(0, 399); str += ".."; } alert('readystate: ' + req.readyState + '\n' + 'status/statusText: ' + req.status + '/' + req.statusText + '\n' + 'responseText (400 chars): ' + "\n\n" + str); } }; req.open('GET', "http://localhost/madonna/1.php", true); req.send(null); } function openInBrowser(url) { air.navigateToURL( new air.URLRequest(url)); } </script> </head> <body> <h3>Application Sandbox Content</h3> <ul> <li>Has access to AIR APIs: <input type="button" id="btn1" onclick="doRequest()" value="Log" /> </body> </html>
-
13 Apr 2009 5:39 PM #8
A request is given but no response it no data arrives
this is wat i get
GET http://localhost/madonna/1.php
-
readyState 1
async true
responseText
-
1
EOF
responseXML
you see there is no response...
-
13 Apr 2009 6:06 PM #9
all your JS code looks fine and the fact that you received a response, albeit blank, means your AIR app is making a successful connection to your server (localhost). At this point, I have to say it is your PHP script: does it require parameters to be sent in order for it to return data? Does it matter if its a GET or POST request?
(edited for typos)
-
13 Apr 2009 8:22 PM #10
no it does not matter whether it is get or post for me. I gave try regarding a simple try either like this
I would been happier if i get this response to but no.Code:echo '{success:true}';


Reply With Quote