submitting a form to the server as json - sencha-touch

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)}
});

Related

Bandcamp api: What POST info do you send, when querying the my_bands endpoint?

https://bandcamp.com/developer/account#my_bands
It doesnt say what youre sposta send, as POST, and if you send without a POST or empty array, you get a 'must be POST' error. Their support isnt helping.
I have been able to use their other endpoints, so I know I've got the auth correct.
I send an empty payload to https://bandcamp.com/api/account/1/my_bands, like:
var parameters = {
headers: { Authorization: 'Bearer '+access_token },
method: 'post',
payload: '',
muteHttpExceptions: true // we want to handle exceptions gracefully
};

How to properly read POST params with express?

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'})

XPages: dijit.Tree dojo.xhrPost and Partial Refresh?

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.

How to use an API

I'm studying Informatics but somehow I don't get that one.
I want to set up the PayPal NVP-API.
(NVP = Name value Pair).
Can someone tell me how I can CALL an API-Command?
I don't even know which programming language I have to take :S
Reference to the Tutorial: PayPal NVPAPI Developer Guide
It sounds like you might be a bit over your head on this one, but don't worry it's not that difficult.
When they say POST they literally mean an HTTP POST, but since its SSL you'd need to provide credentials also.
jQuery AJAX http://api.jquery.com/jQuery.ajax/ would be a good place to start..
$.ajax({
url : 'paypalurl',
type : 'POST', //IMPORTANT
username : 'username',
password : 'password',
data : 'YOUR DATA HERE' //form or something of the like
success : function(r) {
//handle the success here
},
error : function(e) {
//uh-oh
}
});
This should get you started, but please be careful this is financial data.

dojo.io.iframe.send does not send a request on second time onwards in dojo 1.8

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,
});