-
13 Jul 2011 10:49 PM #1
ExtJS 3.4 + JSON + PHP request and response
ExtJS 3.4 + JSON + PHP request and response
Sory about my english... but I'll try
How can I send request and respons from ExtJS 3.4 with formul and response via PHP JSON?
-
14 Jul 2011 12:15 AM #2
try this:
Code:Ext.Ajax.request({url: '/login/login',params:{user: Ext.getCmp('ioUser').getValue(),pass: Ext.getCmp('ioPwd').getValue() },method:'POST', success: function(result, request){var res = new Object();res = Ext.util.JSON.decode(result.responseText); if(res.login == false){ Ext.MessageBox.alert('Warning',res.message);}else{ location.href = '/main/index' }}});
-
14 Jul 2011 3:31 AM #3
-
14 Jul 2011 4:42 AM #4
It's a simple example of an Ext.Ajax.request() submitting to a PHP page and processing the JSON response.
If you were after something specific, you need to be more specific about your request.
-
14 Jul 2011 7:40 AM #5
This request sends data via a POST (the form) twice:PHP Code:var obj1 = Ext.PanelForm( id: 'formObj1', ....);
Ext.getCmp('formObj1').getForm().submit({
clientValidation: true,
method: 'POST',
url: ['serverPHP_extjsjson_url'], // <--- some url action
params: 'data='+'{\"data\": '+Ext.encode(Ext.getCmp('formObj1').getForm().getValues())+'}',
text: 'Updating...', // <--- to procesing whaiting
success: function(form, action) {
Ext.Msg.alert('Success', action.result.msg);
},
failure: function(form, action) {
switch (action.failureType) {
case Ext.form.Action.CLIENT_INVALID:
Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
break;
case Ext.form.Action.CONNECT_FAILURE:
Ext.Msg.alert('Failure', 'Ajax communication failed');
break;
case Ext.form.Action.SERVER_INVALID:
Ext.Msg.alert('Failure', action.result.msg);
}
}
});
- Once by submit
- The second time in a compressed JSON format
I want to send the data only by using JSON. How can I do?
-
14 Jul 2011 7:47 AM #6
Don't use the form.submit() method to "submit". Use Ext.Ajax.request(). That will prevent the double submission.
-
14 Jul 2011 7:56 AM #7
when I use Ext.Ajax.request () is always a form will be sent without checking the validation and how I use form.submit () form will be checked whether the data have been introduced and if so, submit
-
14 Jul 2011 11:40 AM #8
Then you've got several options to choose from:
1. Ext.override( Ext.form.FormPanel, submit: ... ) to submit a single JSON object, instead of an array of key/val pairs
2. Ext.extend( Ext.form.FormPanel, submitJSON: ... ) to create a new submission routine for forms
3. If ( form.isValid() ) Ext.Ajax.request( ... ) to validate the form prior to submitting
4. Use submit() the way it was intended, and fix your PHP processor to accept POST/GET instead of a JSON object.
-
14 Jul 2011 3:06 PM #9
How can I send it by POST in array? How can I send Array not each individual formul element?4. Use submit() the way it was intended, and fix your PHP processor to accept POST/GET instead of a JSON object.
<input name="inp1">
<input name="inp2">
$_POST['myData'] = array('inp1' => 'value1', 'inp2' => 'value2');
-
14 Jul 2011 3:14 PM #10
You can't use Javascript/ExtJS to send a PHP array to a PHP processor, but you can process the $_POST array programmatically.
However, doing that is a discussion for a different forum.


Reply With Quote