PDA

View Full Version : I need Help about CRUD ExtJS PHP Mysql



masoud_tamizy
18 Jan 2012, 1:19 AM
i use ajax proxy for filling Grid from PHP server . but i couldn't do it & i encountered this error message (image in follow link) :

30789

please help me and describe me what is "dc=1326..." in query string?
and how can i do it .
and i need an example for CRUD with Ajax .
...
i need this code to fetch data to Grid :


//Ext.require('*');
Ext.require([
'Ext.data.*',
'Ext.grid.*',
'Ext.panel.*',
'Ext.form.*',
'Ext.util.*',
'Ext.state.*'
]);

Ext.onReady(function() {
var types = Ext.data.Types; // allow shorthand type access
Ext.define('user', {
extend: 'Ext.data.Model',
fields: [
{ name: 'national_code', type: 'string' },
{ name: 'user_id', type: 'int' },
{ name: 'first_name', type: 'string' },
{ name: 'last_name', type: 'string' },
{ name: 'father_name', type: 'string' },
{ name: 'sh_sh', type: 'string' },
{ name: 'sh_s_sh', type: 'string' },
{ name: 'gender', type: 'string' },
{ name: 'birth_date', type: 'date' },
{ name: 'birth_location', type: 'string' },
{ name: 'email', type: 'email' },
{ name: 'home_address', type: 'string' },
{ name: 'home_phone', type: 'string' },
{ name: 'postal_code', type: 'string' },
{ name: 'job_title', type: 'string' },
{ name: 'job_address', type: 'string' },
{ name: 'job_phone', type: 'string' },
{ name: 'mobile', type: 'string' },
{ name: 'fax', type: 'string' },
{ name: 'comment', type: 'string' }
],
validations: [
{type: 'presence', field: 'national_code'},
{type: 'presence', field: 'first_name'},
{type: 'presence', field: 'last_name'},
{type: 'presence', field: 'father_name'},
{type: 'length', field: 'first_name', min: 1, max:45},
{type: 'length', field: 'last_name', min: 1, max:45},
{type: 'length', field: 'father_name', min: 1 , max:45},
{type: 'inclusion', field: 'gender', list: ['Male', 'Female']},
{type: 'exclusion', field: 'username', list: ['Admin', 'Operator']}
]
});
var userstore = Ext.create('Ext.data.Store', {
id:'userstore',
model: 'User',
autoLoad: true,
autoSync: true,
proxy: {
type: 'ajax',
actionMethods: 'POST',
url : 'prepare.php',
reader : {type:'json',root:'users',successProperty: 'success'}
}
});
// Create the Grid
Ext.create('Ext.grid.Panel', {
store: userstore,
selType: 'rowmodel', // 'cellmodel'
loadMask: true,
plugins: [Ext.create('Ext.grid.plugin.RowEditing', {
clicksToEdit: 1,
errorSummary:true})
],
columns: [
{ dataIndex: 'national_code',
hideable: false,
header:'کدملّي',
align:'right' ,
editor : null
},{ dataIndex:'first_name',
text:'نام',
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'last_name',
text:'فاميل',
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'father_name',
text:'نام پدر',
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'sh_sh',
text:'شماره شناسنامه',
align:'right',
sortable:false,
editor: {xtype:'numberfield',allowBlank: false}
},{ dataIndex:'sh_s_sh',
text:'شماره سريال شناسنامه',
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'birth_date',
text:'تاريخ تولذ',
hidden:true,
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'birth_location',
text:'محل تولد',
hidden:true,
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'email',
text:'پست الکترونيک',
hidden:true,
align:'right',
editor: {xtype:'textfield',allowBlank: false}
},{ dataIndex:'home_address',
text:'آدرس منزل',
align:'right'
},{ dtatIndex:'home_phone',
text:'تلفن منزل',
align:'right'
},{ dataIndex:'postal_code',
text:'کد پستي',
align:'right',
},{ dataIndex:'job_title',
text:'شغل',
align:'right',
hidden:true
},{ dataIndex:'job_address',
text:'آدرس محل کار',
align:'right',
hidden:true
},{ dataIndex:'job_phone',
text:'تلفن محل کار',
align:'right',
},{ dataIndex:'mobile',
text:'تلفن همراه',
align:'right'
},{ dataIndex:'fax',
text:'فاکس',
align:'right'
},{ dataIndex:'comment',
text:'توضيحات',
align:'right',
hidden:true
}],
title: 'User List',
height:575,
width:1366,
renderTo: Ext.getBody()
});
});

mitchellsimoens
18 Jan 2012, 6:23 AM
The browser is preventing you from using ajax proxy because you are trying to execute it cross-origin meaning your app isn't loaded on localhost. So you either need to load your app on localhost or use the jsonp proxy.

masoud_tamizy
18 Jan 2012, 6:36 AM
thanks for your attention .
!!! i'm using Localhost to execute this app !!!
but why this happend ???

mitchellsimoens
18 Jan 2012, 6:39 AM
You are launching from http://localhost/ ?

masoud_tamizy
18 Jan 2012, 7:05 AM
You are launching from http://localhost/ ?

Yes I do it . how can i do it with ajax proxy on localhost ?

mitchellsimoens
18 Jan 2012, 7:15 AM
Check your Access-Control-Allow-Origin setting in Apache... is it blank? If so it needs '*'

masoud_tamizy
18 Jan 2012, 7:46 AM
Check your Access-Control-Allow-Origin setting in Apache... is it blank? If so it needs '*'
thank you . i'm using WampServer 1.6.0 . where can i do it ?

hendricd
18 Jan 2012, 8:33 AM
Read and heed: http://stackoverflow.com/questions/5469440/jquery-ajax-request-from-local-filesystem-windows-file

masoud_tamizy
18 Jan 2012, 10:45 PM
thank you very much .
who know what is this "_dc" in my query string :
http://localhost/Banking/prepare.php?_dc=1326955410989

vahid4134
19 Jan 2012, 5:07 AM
thank you very much .
who know what is this "_dc" in my query string :
http://localhost/Banking/prepare.php?_dc=1326955410989





This _dc for disable browser cache

http://docs.sencha.com/ext-js/4-0/#!/api/Ext.data.proxy.Server-cfg-noCache

masoud_tamizy
19 Jan 2012, 6:33 AM
Please help me to Implementing CRUD in Grid with PHP Mysql in my Code ...