var resource_store = Ext.create('Ext.data.Store', {
pageSize: 10,
autoLoad: true,
fields: ['id','r_number','c_number','resource_name','resource_desc','resource_url','resource_file'],
proxy: {
type: 'ajax',
url: BASE_URL+'courses/resources/displayResources/'+course_id,
reader: {
type: 'json',
root: 'results'
}
},
storeId: 'id'
});
I'm using Extjs4 data store like this way.
When i see the ajax calls a random number is appended to the url
http://localhost/Edu_web/index.php/courses/resources/displayResources/PTGRE14?_dc=1328442262503&page=1&start=0&limit=10
Even though i use
actionMethod:{
read: 'POST'
}.
?_dc=1328442262503 still appears in the url.
how to remove these parameters in url. and send any parameters through POST
Even though i use actionMethod:{ read: 'POST' }.
?_dc=1328442262503 still appears in the url.
Of course it would. You should use actionMethods (with 's' at the end).
To remove _dc from GET request you should add noCache: false to proxy's config. Docs for noCache.
P.S. Using a POST for reading is a bad practise. You should only use a POST when you are modifying data on the server.
If there are any proxy in your network, before disabling the random number, check to see if they have caching disabled, otherwise the client, instead of downloading the updated pages from the server, will continue to read the previous ones stored in the proxy. The random number added to the call makes it different each time and the proxy will be forced to always download it from the server
Related
My node app is supposed to POST to an external server, so I'm playing with request from NPM. I want to verify it's working, but I'm not entirely sure I'm doing that right.
I've tried both of these methods
request({
url: url,
method: 'POST',
form: { a: 1}
}
request({
url: url,
method: 'POST',
json: true,
body: { a: 1}
}
In my test when I hit my own server, req.body shows the right object when I do json true. However that just means I'm passing a JSON header. The API I actually need to hit is expecting a normal POST, not JSON.
So when I try to verify that request is working right when I use form, my server says req.body is an empty object.
EDIT
I am posting to external API fine using form, but on my own server, express is leaving request.body as empty object.
See if this works for you:
request.post('http://service.com/upload').form({key:'value'})
I have a dijit.Tree which works fine. Users can add, delete and rename nodes on this tree (jsfiddle) if they have special authorization on it.
The next step is to post this changes back to the server, which works perfect, using dojo.xhrPost in conjunction with an XAgent (instead of an XAgent this functionality could be achieved using extension library control for REST-Services of type customRestService. However, this is not available until domino version 9...)
Source code:
<xp:button value="Submit tree updates back to server " id="btnSubmit">
<xp:this.onclick><![CDATA[dojo.xhrPost({
url: "folderService.xsp", // XAgent
handleAs: "json",
timeout: 1000,
postData: treeStore._getNewFileContentString(), // treeStore
headers: { "Content-Type": "application/json", "Accept": "application/json" },
load: function(data) {
if (data.success) {
console.log("all folders saved " + data.success);
dojo.byId("#{id:txtMessage}").innerHTML = data.message; ???
dojo.removeClass("#{id:txtMessage}", "lotusHidden"); ???
XSP.partialRefreshGet("#{id:wrapper}", {}); ???
}
},
error: function() {
dojo.byId("#{id:txtMessage}").innerHTML = 'Oops something goes wrong. The update on the folders weren\'t saved.'; ???
dojo.removeClass("#{id:txtMessage}", "lotusHidden"); ???
XSP.partialRefreshGet("#{id:wrapper}", {}); ???
}
});]]></xp:this.onclick>
</xp:button>
Now the question:
I have the requirement to show some information to the user which comes back from the server (load : function(data) {...}).
Possible solutions:
Do it only on client side (e.g. dojo.byId("#{id:txtMessage}").innerHTML = data.message;)?
Pros: No partial refresh needed
Cons: I can't work with already implemented custom controls (e.g. computed rendered property)
Do some partial refresh after a successfull xhrPost?
If this is the right choice, how and were I should implement a partial refresh after a successfull xhrPost?
My feeling says no, because why I should do a partial refresh only for the
making information visible (e.g. rendered property...).
Do something else?
I am not sure which is the best approach to handle my requirements?
Hint: I am working on a Domino Sever 8.5.3 FP6
Thanks in advance for any answer.
I am trying to get all Books from the server (local PHP script), that has a book ID of 1.
I think i will have to send a GET request with ID 1, so that the PHP script will return the records for ID 1.
When i searched i found out that i should make use of Ext.ModelManager.getModel to get this done. But i am unable to find any examples that would help me to do this.
Can someone help me out.
In your store, add proxy and set extraParams.
proxy: {
type: 'ajax',
url: 'your url'
},
listeners: {
'beforeload': function (t,n) {
this.proxy.extraParams.Id = yourId
},
Is there a way to output the json-string read by my store in sencha touch 2?
My store is not reading the records so I'm trying to see where went wrong.
My store is defined as follows:
Ext.define("NotesApp.store.Online", {
extend: "Ext.data.Store",
config: {
model: 'NotesApp.model.Note',
storeId: 'Online',
proxy: {
type: 'jsonp',
url: 'http://xxxxxx.com/qa.php',
reader: {
type: 'json',
rootProperty: 'results'
}
},
autoLoad: false,
listeners: {
load: function() {
console.log("updating");
// Clear proxy from offline store
Ext.getStore('Notes').getProxy().clear();
console.log("updating1");
// Loop through records and fill the offline store
this.each(function(record) {
console.log("updating2");
Ext.getStore('Notes').add(record.data);
});
// Sync the offline store
Ext.getStore('Notes').sync();
console.log("updating3");
// Remove data from online store
this.removeAll();
console.log("updated");
}
},
fields: [
{
name: 'id'
},
{
name: 'dateCreated'
},
{
name: 'question'
},
{
name: 'answer'
},
{
name: 'type'
},
{
name: 'author'
}
]
}
});
you may get all the data returned by the server through the proxy, like this:
store.getProxy().getReader().rawData
You can get all the data (javascript objects) returned by the server through the proxy as lasaro suggests:
store.getProxy().getReader().rawData
To get the JSON string of the raw data (the reader should be a JSON reader) you can do:
Ext.encode(store.getProxy().getReader().rawData)
//or if you don't like 'shorthands':
Ext.JSON.encode(store.getProxy().getReader().rawData)
You can also get it by handling the store load event:
// add this in the store config
listeners: {
load: function(store, records, successful, operation, eOpts) {
operation.getResponse().responseText
}
}
As far as I know, there's no way to explicitly observe your response results if you are using a configured proxy (It's obviously easy if you manually send a Ext.Ajax.request or Ext.JsonP.request).
However, you can still watch your results from your browser's developer tools.
For Google Chrome:
When you start your application and assume that your request is completed. Switch to Network tab. The hightlighted link on the left-side panel is the API url from which I fetched data. And on the right panel, choose Response. The response result will appear there. If you have nothing, it's likely that you've triggered a bad request.
Hope this helps.
Your response json should be in following format in Ajax request
{results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]}
id and name are properties of your model NOte.
For jsonp,
in your server side, get value from 'callback'. that value contains a name of callback method. Then concat that method name to your result string and write the response.
Then the json string should be in following format
callbackmethod({results:[{"id":"1", "name":"note 1"},{"id":"2", "name":"note 2"},{"id":"3", "name":"note 3"}]});
It seems there is a problem with loading a specific instance (load() function) using the rest proxy in a model/store object. example:
Code:
Ext.regModel('User', {
fields: ['id', 'name', 'email'],
proxy: {
type: 'rest',
url : '/users'
}
});
//get a reference to the User model class
var User = Ext.ModelMgr.getModel('User');
//Uses the configured RestProxy to make a GET request to /users/123
User.load(123, {
success: function(user) {
console.log(user.getId()); //logs 123
}
});
This code is copied from Sencha touch's API. the generated URL is http://localhost/users?_dc=... instead of the desired (and documented) url http://localhost/users/123.
it also happens when using the store.load with a parameter.
Am I doing something wrong here?
Thanks
T
It seams the id parameter has been documented but not implemented. This has been discussed in the sencha forum [link]. A few non complete fixes are written in post #8 and post #13.