PDA

View Full Version : Can't update edits using AJAX.



gregwhitworth
2 Apr 2011, 5:16 PM
Ok. I am following the PHP + SQl tutorial and everything is working fine until I try to update the information. I am using the ZEND framework and I have turned off the layout and view for the action so it should be working. Anyways, here is my JS that saves the update (PS: The Ext.MessageBox.alert says it can't connect to the db but I have a non-extJS version and it works fine):

JS


function saveContact(oGrid_event){
Ext.Ajax.request({
waitMsg: 'Please wait...',
url: 'http://localhost/msi-contacts/public/contact/ajaxUpdate/',
method: 'POST',
params: {
id: oGrid_event.record.data.id,
first_name: oGrid_event.record.data.first_name,
last_name: oGrid_event.record.data.last_name
},
success: function(response){
var result=eval(response.responseText);
switch(result){
case 1:
ContactDataStore.commitChanges(); // changes successful, get rid of the red triangles
ContactDataStore.reload(); // reload our datastore.
break;
default:
Ext.MessageBox.alert('Uh uh...','We couldn\'t save him...');
break;
}
},
failure: function(response){
var result=response.responseText;
Ext.MessageBox.alert('DB Error','Could not connect to the database. retry later');
}
});
}


PHP



public function ajaxUpdateAction()
{
$this->_helper->viewRenderer->setNoRender();
$this->_helper->getHelper('layout')->disableLayout();

foreach( $_POST as $key=>$value ) {
$data[$key] = $value;
}

$contacts = new Application_Model_DbTable_Contacts();
$contacts->updateContact($data);
}

gregwhitworth
3 Apr 2011, 1:13 PM
So does no one see anything wrong with my JS. Then it must be Zend causing the problem, does anyone know why??

steffenk
3 Apr 2011, 1:26 PM
why doing that manually if you could do it right away with the store?
store.commit() would fire a request for update if you configured it right.

look into the docs, it's described how to do
http://dev.sencha.com/deploy/dev/docs/?class=Ext.data.DataWriter

gregwhitworth
3 Apr 2011, 1:47 PM
Thanks for that but I don't see how I can pass the data that needs to be updated. In the tutorial I was following it does this:

params: {
id: oGrid_event.record.data.id,
first_name: oGrid_event.record.data.first_name,
last_name: oGrid_event.record.data.last_name
}

So how would I do that with the writer, I mean how does it know which record to delete??

steffenk
3 Apr 2011, 1:53 PM
the record gets dirty flag if you change the data, so store sends records that are dirty.