PDA

View Full Version : Problems on the server with requests and PUT and DELETE



Valik71
20 Apr 2013, 11:37 AM
I created a table for ExtJS 4.2.0 On localhost there is no problem and it works. When transferring to the server appears incomprehensible situation. The server is not working.
I add, edit and delete records from MySQL REST way.


var store = Ext.create('Ext.data.Store', {
autoLoad: true,
autoSync: true,
model: 'Row',
proxy: {
type: 'rest',
url: '../php/main.php',
reader: {
type: 'json'
},
writer: {
type: 'json'
}
}
});

Get the data from the database using method GET, add and change - the method PUT, delete - DELETE.
Method GET works fine. http://eht.****.org/php/main.php?_dc=1366485228023&page=1&start=0&limit=25
With PUT and DELETE - problem. http://eht.****.org/php/main.php/2?_dc=1366485321278
What is this : main.php/2?

krullj
21 Apr 2013, 12:43 PM
It looks like the "2" might be the ID of the record you're trying to use PUT or DELETE on. That's just how REST works. It's helpful that you put the ExtJS version, but overall you didn't provide enough information for someone else to help you solve the problem.

Valik71
22 Apr 2013, 12:25 AM
And what information is needed? On my localhost everything works, moved to a remote server, and that's a mistake.

krullj
22 Apr 2013, 4:55 AM
Sorry, I should have been more specific in my first post. Basically anything another person would need to set up a test to see if they can reproduce your problem. For instance, your store has a model of "Row" but we don't know what that looks like or have a sample of the data you're working with. What methods you called to actually make the PUT and DELETE requests happen would be helpful as well.

Valik71
22 Apr 2013, 5:58 AM
Sorry for my english.
My link http://auto-pcl.org/row.html
Try to remove or edit the line.This will cause an error.
My PHP:

$data_req = (isset($_REQUEST['data'])) ? json_decode(stripslashes($_REQUEST['data'])) : null;
if (isset($_REQUEST['data'])) {
$data_req = json_decode(stripslashes($_REQUEST['data']));
}
else {
$data_req = json_decode(file_get_contents('php://input'));
}

switch ($_SERVER["REQUEST_METHOD"])
{
case 'GET':

$result = mysql_query("SELECT * FROM `$table` ORDER BY `id` ASC", $con);
while ($row = mysql_fetch_assoc($result)) {
for ($i=0; $i < mysql_num_fields($result); $i++) {
$meta = mysql_fetch_field($result, $i);
}
$rows[] = $row;
}
echo json_encode($rows);
break;

case 'PUT':

foreach ($data_req as $field => $value) $data[$field] = $value;
$rowindex = ($data['id']!=null) ? $data['id'] : 0;

if ($rowindex==0) {
unset($data['id']);
$t = "INSERT INTO `$table` (";
foreach ($data as $field => $value) $t.="`$field`,";
$t = substr ($t, 0, -1);
$t.=") VALUES (";
foreach ($data as $value) $t.="'$value',";
$t = substr ($t, 0, -1);
$t.=")";
}
else{
$t = "UPDATE `$table` SET ";
foreach ($data_req as $field => $value) $t = $t."`$field` = '$value',";
$t = substr($t,0,-1);
$t = $t . " WHERE `id` = ".$rowindex;
}
mysql_query($t);

break;

case 'DELETE':

foreach ($data_req as $field => $value) $data[$field] = $value;
$id = isset($data['id']) ? $data['id'] : 0;
$result = mysql_query("DELETE FROM `$table` WHERE `id`= $id", $con);
mysql_query($result);
break;

default:
break;
}
Once again I say that on Localhost it works for me. I tried on different servers and everywhere there is an error.
Model.

Ext.define('Row', {
extend: 'Ext.data.Model',
fields: [
{name: 'id', type: 'int', useNull: true},
{name: 'descr', type: 'int'},
{name: 'sched', type: 'int'},
{name: 'change', type: 'int'},
{name: 'prev', type: 'int'},
{name: 'thisp', type: 'int'},
{name: 'stored', type: 'int'},
{name: 'retainage', type: 'int'}
]
});




var grid = Ext.create('Ext.grid.Panel', {
store: store,
renderTo: 'grid1',
//width: 800,
height: 400,
layout: 'fit',
style: 'padding: 20px',
title: '<h2>CONTINUATION </h2>',
plugins: [rowEditing],
iconCls: 'icon-grid',
features: [{
ftype: 'summary'
}],

columns: [
Ext.create('Ext.grid.RowNumberer'),
{
/*xtype: 'rownumberer',
renderer: function (v, p, record, rowIndex) {
if (this.rowspan) {
p.cellAttr = 'rowspan="' + this.rowspan + '"';
}
return rowIndex + 1;
},*/
text : 'ID',
width : 50,
dataIndex: 'id',
summaryRenderer: function(){ return '<strong>Totals:</strong> ';}
},
{
text : 'Description of work',
flex: 1,
dataIndex: 'descr',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
},
{
text : 'Scheduled value',
width : 90,
dataIndex: 'sched',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
},
{
text : 'Change orders to data',
width : 120,
dataIndex: 'change',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
},
{
text : 'Adjusted scheduled values',
width : 140,
dataIndex: 'adjusted',
renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
return record.get('sched') + record.get('change');
},
summaryType: function(records){
var i = 0,
length = records.length,
total = 0,
record;

for (i = 0; i < length; ++i) {
record = records[i];
total += record.get('sched') + record.get('change');
}
return total;
},
summaryType: 'sum'
},
{
text : 'Work Completed',
columns: [{
text : 'Previous Application',
width : 110,
dataIndex: 'prev',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
}, {
text : 'This period',
width : 65,
dataIndex: 'thisp',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
}]

},
{
text : 'Materials presently stored',
width : 135,
dataIndex: 'stored',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
}
},
{
text : 'Total Completed and Stored to Data',
width : 185,
dataIndex: 'total',
renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
return record.get('prev') + record.get('thisp') + record.get('stored');
},
summaryType: function(records){
var i = 0,
length = records.length,
total = 0,
record;

for (i = 0; i < length; ++i) {
record = records[i];
total += record.get('prev') + record.get('thisp') + record.get('stored');
}
return total;
},
summaryType: 'sum'
},
{
text : '% complete',
width : 70,
dataIndex: 'perComplete',
renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
return Math.floor((record.get('sched') + record.get('change')) / (record.get('prev') + record.get('thisp') + record.get('stored')) * 100);
},
summaryType: function(records){
var i = 0,
length = records.length,
total = 0,
record;

for (i = 0; i < length; ++i) {
record = records[i];
total += record.get('sched');
}
return total/length;
},
summaryType: 'sum'
},
{
text : 'Balance to Finish',
width : 90,
dataIndex: 'balance',
renderer: function(value, metaData, record, rowIdx, colIdx, store, view) {
return (record.get('sched') + record.get('change')) - (record.get('prev') + record.get('thisp') + record.get('stored')) ;
},
summaryType: function(records){
var i = 0,
length = records.length,
total = 0,
record;

for (i = 0; i < length; ++i) {
record = records[i];
total += (record.get('sched') + record.get('change')) - (record.get('prev') + record.get('thisp') + record.get('stored'));
}
return total;
},
summaryType: 'sum'

},
{
text : 'Retainage to date',
dataIndex: 'retainage',
field: {
xtype: 'textfield'
},
summaryType: 'sum',
summaryRenderer: function(value, summaryData, dataIndex) {
return value;
},
}
],

dockedItems: [{
xtype: 'toolbar',
items: [{
tooltip: 'Add a new row',
text: 'New row',
iconCls: 'add',
handler: function(){
// ?????? ??????
store.insert(0, new Row());
rowEditing.startEdit(0, 0);
}
}, '-', {
itemId: 'delete',
tooltip: 'Delete selected row',
text: 'Delete row',
iconCls: 'delete',
disabled: true,
handler: function(){
var selection = grid.getView().getSelectionModel().getSelection()[0];
if (selection) {
store.remove(selection);
}
}
}]
}]
});
grid.getSelectionModel().on('selectionchange', function(selModel, selections){
grid.down('#delete').setDisabled(selections.length === 0);
});