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.
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 am having an issue getting relations backing using the deep parameter.
I'm using this url and am expecting it to return my related objects but is not.
url: Backand.getApiUrl() +"/1/objects/blogs?deep=true",
Yes, the deep works only for specific item because of performance reasons.
You should do /1/objects/blogs/1?deep=true
In general we suggest to query the blogs and from the client using promise to get the deep of each one.
If you must get it all at once, you can create server side on demand action, make the query and loop on the results while populating it with the deep. Because it runs on the server side it will be fast. here is a code example for the server-side action:
function backandCallback(userInput,dbRow,parameters,userProfile){
var response=$http({
method: "GET",
url: CONSTS.apiUrl+"/1/objects/blogs",
headers: {
"Authorization": userProfile.token
}
});
var mapping=response.data.map(function(item){
var object=item;
var user=$http({
method: "GET",
url: CONSTS.apiUrl+"/1/objects/users/"+item.author,
headers: {
"Authorization": userProfile.token
}
});
object.author_obj=user;
return object;
})
return mapping;
}
I am trying to submit a form to the server with the params in JSON.
form.submit({
url:'JSONSaveEntry',
method:'POST'
});
but it sends everything as form-www-urlencoded.
I already checked that no field has isFile set to true (but then, it would send as multipart-formdata) and that standardSubmit is false.
I also tried to use
Ext.Ajax.request({
url:'JSONSaveEntry',
method:'POST',
params:form.getValues()
});
and
Ext.Ajax.request({
url:'JSONSaveEntry',
method:'POST',
params:Ext.encode(form.getValues())
});
Every submission is done as form-www-urlencoded, although the docs clearly state "Performs a Ajax-based submission of form values (if standardSubmit is false)". But then, this sentence is already proven wrong because whenever a file field is in the form, the form is submitted as multipart.
So, does anyone know how I can get the form submitted as JSON?
Possibility 2: I know that it works if I submit a model via model.save(), but how would I create a model from a form on-the-fly (without hardcoding the fields twice)?
I think below would solve your purpose.
Ext.Ajax.request({
url:'JSONSaveEntry',
method:'POST',
headers: { 'Content-Type': 'application/json' },
jsonData : JSON.stringify(form.getValues()),
success : function(response){ console.log("response from server")},
failure : function(error){console.log(error)}
});
Example code snippet
this._deferred = dojo.io.iframe.send({
url: "/Some/Servie",
method: "post",
handleAs: 'html',
content: {},
load: function(response, ioArgs){
//DO successfull callback
},
error: function(response, ioArgs){
// DO Failer callback
}
});
Steps
click submit button send a request and successfully got a response
click submit button again...request never send...
Appreciate any help
I can't talk for 1.8, but I am using dojo 1.6 and had a very similar issue that I resolved with the following method:
dojo.io.iframe._currentDfd = null; //insert this line
dojo.io.iframe.send
({...
*verified in Chrome Version 25.0.1364.152 m
Source: http://mail.dojotoolkit.org/pipermail/dojo-interest/2012-May/066109.html
dojo.io.frame.send will only send one request at a time, so if it thinks that the first request is still processing (whether it actually is or not), it won't work on the second call. The trick is to call cancel() on the returned deferred result if one exists, like so:
if (this._deferred) {
this._deferred.cancel();
}
this._deferred = dojo.io.iframe.send({
....
that will cancel the first request and allow the second request to send properly.
For dojo 1.8, dojo.io.iframe is deprecated. dojo.request.iframe is used instead.
And the solution from #Sorry-Im-a-N00b still works:
iframe._currentDfd = null;
iframe.get(url, {
data: sendData,
});
I am trying to use the following to do a cross-domain get:
dojo.io.script.get({
url: myUrl,
callbackParamName: "callback",
preventCache: true,
load: dojo.hitch( this, loadFunction ),
error: dojo.hitch( this, function() {
console.log('Error!!!');
})
});
The load function runs fine, however, when the server returns a 404, the error function does not run. Can anyone tell me why?
EDIT
After some investigation, I found that a timeout and handler could be implemented in the following way:
dojo.io.script.get({
url: myUrl,
callbackParamName: "callback",
timeout: 2000
}).then(function(data){
console.log(data);
}, function(error){
alert(error);
});
This uses functionality provided by the dojo.Deferred object.
When accessing server with script tags (that what dojo.io.script.get does), status code and headers are not available.
You may try some other ways to detect a problem, like using a timeout and analyzing a content of a script. The latter is problematic for JSONP calls (like in your example).
I realize this is old but I thought I'd share a solution in case others, like I had, come across this thread.
dojo.io.script is essentially adding a <script/> to your html page. So you can try this:
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', myUrl);
script.onerror = function() {
debugger
}
script.onload = function() {
debugger
}
document.getElementsByTagName('body')[0].appendChild(script);
That way if the script fails to load the onerror event is called.
*This may not work in every instance but is a good start