PDA

View Full Version : [CLOSED] Store problem with jsonp proxy when insert, update,delete



mtsig
Jul 23, 2013, 2:13 PM
Hello, in the code example i have a store with setup for server calls with proxy jsonp.

The problem is that when the sync command executes the server calls executed ok but the header params are not in array but it is different param every field.
I made the same example with extjs and when jsonwriter has the encode=true the fields come in server inside array.

Some help please ?


<ext:Store ID="store_users" runat="server" AutoSync="false" RemoteSort="true" RemoteFilter="true" PageSize="20" >
<Model>
<ext:Model ID="model_users" runat="server" IDProperty="UserId">
<Fields>
<ext:ModelField Name="UserId" Type="String" />
<ext:ModelField Name="UserLoginName" Type="String" />
<ext:ModelField Name="UserLastName" Type="String" />
<ext:ModelField Name="UserFirstName" Type="String" />
<ext:ModelField Name="UserPersonName" Type="String" />
<ext:ModelField Name="UserEMail" Type="String" />
<ext:ModelField Name="UserActive" Type="Boolean" />
<ext:ModelField Name="UserDeleted" Type="Boolean" />
<ext:ModelField Name="UserDomain" Type="String" />
<ext:ModelField Name="UserLastNameGR" Type="String" />
<ext:ModelField Name="UserFirstNameGR" Type="String" />
<ext:ModelField Name="UserDateCreated" Type="Date" />
</Fields>
<Proxy>
<ext:JsonPProxy >
<API Read="users.ashx" Create="users.ashx" Update="users.ashx" Destroy="users.ashx"></API>
<Reader>
<ext:JsonReader Root="data" SuccessProperty="success" MessageProperty="message" TotalProperty="total" />
</Reader>
<Writer>
<ext:JsonWriter Encode="true" WriteAllFields="false" Root="data" />
</Writer>
</ext:JsonPProxy>
</Proxy>
</ext:Model>
</Model>
</ext:Store>

this is the firebug params for the destroy call

UserActive false
UserDateCreated 2008-01-01T00:00:00
UserDeleted false
UserDomain SLG
UserEMail test
UserFirstName test
UserFirstNameGR
UserLastName test
UserLastNameGR ΑΒΓΔΕΖΗΘ
UserLoginName test
UserPersonName test test
_dc 1374587993320
action destroy
callback Ext.data.JsonP.callback2
records UserId=57CE6801E1DF08408026640E71405CDA

and the correct with extjs for destroy is:

_dc 1374588593034
callback Ext.data.JsonP.callback2
data {"UserId":"57CE6801E1DF08408026640E71405CDA"}

Daniil
Jul 23, 2013, 4:45 PM
Hi @mtsig,

Welcome to the Ext.NET forums!

Please post the ExtJS Store configuration code which works as you need.

Could you also clarify why you are using JsonPProxy? The URLs do not look cross-domain.

mtsig
Jul 24, 2013, 6:13 AM
Hello,

I have no specific reason to use jsonp proxy. I just found it in example and use it.

The code of extjs that works :


Ext.define('model_users', {
extend: 'Ext.data.Model',
idProperty: 'UserId', // PRIMARY KEY - A MUST OTHERWISE UPDATE AND DELETE IS NOT WORKING
fields: [ { name: 'UserId', type: 'string' },
{ name: 'UserLoginName', type: 'string' },
{ name: 'UserLastName', type: 'string' },
{ name: 'UserFirstName', type: 'string' },
{ name: 'UserPersonName', type: 'string' },
{ name: 'UserEMail', type: 'string' },
{ name: 'UserActive', type: 'bool' },
{ name: 'UserDeleted', type: 'bool' },
{ name: 'UserDomain', type: 'string' },
{ name: 'UserLastNameGR', type: 'string' },
{ name: 'UserFirstNameGR', type: 'string' },
{ name: 'date2', type: 'date' }
]});



var store_users = Ext.create('Ext.data.Store',{
pageSize: 20, // PAGING SIZE
model: 'model_users',
remoteSort: true, // REMOTE SORTING is enabled and controlled from php
remoteFilter: true, // REMOTE FILTERING is enabled and controlled from php
autoLoad: true, // autoload = true to load data when page is loading first time
autoSync: false, // autosync = false, the button save do all the work

listeners:
{
beforeLoad: function()
{
var grid = Ext.getCmp("my_grid");
grid.setLoading({ msg: "" } );
},
load: function()
{
var grid = Ext.getCmp("my_grid");
grid.setLoading(false);
}
},
proxy: {
type: 'jsonp', // JSONP TYPE OF proxy
api:
{
read: 'app.php/read',
create: 'app.php/insert',
update: 'app.php/update',
destroy: 'app.php/delete',
headers: { 'Content-Type': 'application/json; charset=UTF-8' }
},
reader:
{
type: 'json',
successProperty: 'success',
root: 'data',
totalProperty: 'total',
messageProperty: 'message'
},
writer:
{
type: 'json',
writeAllFields: false,
root: 'data',
encode: true // A MUST, OTHERWISE INSERT and UPDATE do not send to server as array
},
listeners:
{
exception: function(proxy, response, operation) // EXCEPTION IN ERROR
{
Ext.MessageBox.show({ title: 'Server Error', msg: operation.getError(), icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK });
}
}
}
});

Daniil
Jul 24, 2013, 6:32 AM
Thank you.

Please try to replace

<ext:JsonPProxy>

with

<ext:AjaxProxy Json="true">

mtsig
Jul 24, 2013, 8:10 AM
Many thanks

It works as it should with AjaxProxy.

With json why not ? Is it a bug, just to know



Thank you.

Please try to replace

ext:JsonPProxy>

with

<ext:AjaxProxy Json="true">

Daniil
Jul 24, 2013, 11:39 AM
Not sure. Please try this with a JsonPProxy.


<ext:JsonPProxy>
<API Read="users.ashx" Create="users.ashx" Update="users.ashx" Destroy="users.ashx">
<CustomConfig>
<ext:ConfigItem Name="headers" Value="{ 'Content-Type': 'application/json; charset=UTF-8' }" Mode="Raw" />
</CustomConfig>
</API>
...


Does it work as needed?

mtsig
Jul 24, 2013, 1:36 PM
No the same thing. I added to grid two rows and press the save (sync) button.
Below is the header params from the insert request.
The strange thing is that the writer has the property Root="data" but in the header params says records.

UserActive false
UserActive false
UserDateCreated
UserDateCreated
UserDeleted false
UserDeleted false
UserDomain
UserDomain
UserEMail
UserEMail
UserFirstName
UserFirstName
UserFirstNameGR UserId=
UserFirstNameGR
UserLastName
UserLastName
UserLastNameGR
UserLastNameGR
UserLoginName
UserLoginName
UserPersonName
UserPersonName
_dc 1374672640520
action create
callback Ext.data.JsonP.callback2
records UserId=

This is the correct header params request on insert with Ajaxproxy with two records added.

_dc 1374672871807
action create
data [{"UserLoginName":"","UserLastName":"","UserFirstName":"","UserPersonName":"","UserEMail":"","UserActive":false,"UserDeleted":false,"UserDomain":"","UserLastNameGR":"","UserFirstNameGR":""},{"UserLoginName":"","UserLastName":"","UserFirstName":"","UserPersonName":"","UserEMail":"","UserActive":false,"UserDeleted":false,"UserDomain":"","UserLastNameGR":"","UserFirstNameGR":""}]


Not sure. Please try this with a JsonPProxy.


<ext:JsonPProxy>
<API Read="users.ashx" Create="users.ashx" Update="users.ashx" Destroy="users.ashx">
<CustomConfig>
<ext:ConfigItem Name="headers" Value="{ 'Content-Type': 'application/json; charset=UTF-8' }" Mode="Raw" />
</CustomConfig>
</API>
...


Does it work as needed?

Daniil
Jul 24, 2013, 2:09 PM
Does this help?

<ext:JsonWriter ... AllowSingle="true" />

mtsig
Jul 24, 2013, 2:26 PM
Sorry i checked AllowSingle true and false but the same behavior !!



Does this help?

<ext:JsonWriter ... AllowSingle="true" />

Daniil
Jul 24, 2013, 2:32 PM
Seems I don't see any more difference between the ExtJS configuration code and the Ext.NET one.

By the way, what ExtJS/Ext.NET versios are you testing with?

mtsig
Jul 24, 2013, 2:44 PM
Ext.Net Version=2.1.1.11828
Extjs=4.2


Seems I don't see any more difference between the ExtJS configuration code and the Ext.NET one.

By the way, what ExtJS/Ext.NET versios are you testing with?

Daniil
Jul 25, 2013, 4:25 AM
Ext.NET v2.1 is based on ExtJS 4.1. Maybe, it is the reason of the difference.

Could you test with Ext.NET v2.2 (ExtJS 4.2.0) and/or the latest Ext.NET from SVN trunk (ExtJS 4.2.1)?

mtsig
Jul 25, 2013, 7:02 AM
It works with v2.2 (File Version=2.2.0.40838).

Now the header request params on insert two records is this:

_dc 1374735554521
action create
callback Ext.data.JsonP.callback4
data [{"UserLoginName":"","UserLastName":"","UserFirstName":"","UserPersonName":"","UserEMail":"","UserActive":false,"UserDeleted":false,"UserDomain":"","UserLastNameGR":"","UserFirstNameGR":""},{"UserLoginName":"","UserLastName":"","UserFirstName":"","UserPersonName":"","UserEMail":"","UserActive":false,"UserDeleted":false,"UserDomain":"","UserLastNameGR":"","UserFirstNameGR":""}]

Thank you very much. You can close this thread.



Ext.NET v2.1 is based on ExtJS 4.1. Maybe, it is the reason of the difference.

Could you test with Ext.NET v2.2 (ExtJS 4.2.0) and/or the latest Ext.NET from SVN trunk (ExtJS 4.2.1)?