PDA

View Full Version : ExtJS 3.4 + JSON + PHP request and response



luks35
13 Jul 2011, 10:49 PM
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?

boston-george
14 Jul 2011, 12:15 AM
try this:




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'

}

}


});

luks35
14 Jul 2011, 3:31 AM
I dont know how use this
hellp

httpdotcom
14 Jul 2011, 4:42 AM
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.

luks35
14 Jul 2011, 7:40 AM
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);
}
}
});
This request sends data via a POST (the form) twice:
- 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?

httpdotcom
14 Jul 2011, 7:47 AM
Don't use the form.submit() method to "submit". Use Ext.Ajax.request(). That will prevent the double submission.

luks35
14 Jul 2011, 7:56 AM
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

httpdotcom
14 Jul 2011, 11:40 AM
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.

luks35
14 Jul 2011, 3:06 PM
4. Use submit() the way it was intended, and fix your PHP processor to accept POST/GET instead of a JSON object.


How can I send it by POST in array? How can I send Array not each individual formul element?

<input name="inp1">
<input name="inp2">

$_POST['myData'] = array('inp1' => 'value1', 'inp2' => 'value2');

httpdotcom
14 Jul 2011, 3:14 PM
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.

luks35
15 Jul 2011, 5:48 AM
Thanks for your help
I used


3. If ( form.isValid() ) Ext.Ajax.request( ... ) to validate the form prior to submitting

yueheng0112
6 Dec 2011, 12:13 AM
???????

luks35
6 Dec 2011, 2:13 AM
No I cant :/ sorry

yueheng0112
6 Dec 2011, 5:20 PM
????????

luks35
6 Dec 2011, 11:53 PM
??????
???????????