In fine-uploader is there a callback for the json resturned by the server? - fine-uploader

By default fine-uploader marks an upload as a success when it recieves the following json file.
{ "success": "true" }
Does fine-uploader support passing extra data back to the client and doing something with it?

All data passed from your server can be accessed on the 3rd parameter passed to your onComplete event handler, which is a JavaScript object. Note that the `XMLHttpRequest instance used to send the request is also available as the 4th param.

Related

Parse cloud code send flag to save object

I've been trying to send a flag to save request. This save request is sent from different platforms so we seperated them with a flag. The problem is that it gives
Result: TypeError: Cannot read property '0' of undefined
when you send the request to table without the parameter. I did not want to add this parameter as a column in the table but it seems it automatically creates it when you successfully save the object. Is there a way to save the object without creating the flag column and seperate the save requests with and without the flag? Thank you in advance.
Parse.Cloud.beforeSave("MessageTest", function(request, response) {
if(!request.object.get("fromMessages")) {
..
..
}
else response.succcess();
});
If you try to save an object directly from your app, you cannot remove the field from your request in beforeSave trigger. A better approach is to save your object via a Cloud function instead. Send in your object alongside of your platform flag to a cloud function, then construct a MessageTest object from the parameters (obviously ignoring your platform flag) and then save it from there.

temporarily change $http.defaults.transformResponse

How can I customize $http in angularjs such that it will accept strings as its response in a $http.post call? Right now, when I do a $http.post call, my response is in string but angularjs by default uses JSON therefore I get an error. Right now I have something along the lines of
function getResponseURL(response) {
//this will convert the response to string
return response;
}
$http.defaults.transformResponse = [];
$http.defaults.transformResponse.unshift(getResponseURL);
However if I use the code above, any $http.post calls after that call uses string. I want it to use the original default JSON format. How can I go about into just temporarily changing the response to string for this one call but the rest stay as JSON type as a response?
Why not only register that transform for ONLY that request?
Angular js $http docs
If you wish
override the request/response transformations only for a single
request then provide transformRequest and/or transformResponse
properties on the configuration object passed into $http.

How to send Object via Ajax to Servlet

How do I send an element of type object via ajax to a servlet?
In the ajax I am passing the value as follows below:
data: { mapList : mapLists }
To get the value in the Servlet am doing follows below:
Object o = request.getAttribute("mapList");
System.out.println(o);
However, the returned value is always null. What should I do to get around this problem?
Change your ajax datas by :
data: { 'mapList' : mapLists }
On HTTP GET or POST requests you can only send a list of key/value pairs as parameters to the server so you will have to manually serialize your object to send its attributes in this format.
You should better use HttpServletRequest.getParameter(String) in place of HttpServletRequest.getAttribute(String). Also, what you get as an HTTP GET/POST parameter will always be received in the servlet as a String.
I assume that you are using jQuery to send the ajax request. I also asume that your mapLists variable is a json object. As far as I know, jQuery doesn't automatically convert a json object to a key/value pair HTTP parameter list so you will have to do it by yourself and then parse it back in the servlet. You can use JSON.stringify() to convert your json object or you can serialize it manually.

Checking the type of POST data received in Sinatra

In my sinatra app i have a form which is used to submit data via a POST request to a url.The url also accepts json sent in a POST request.
Is there any way to determine in the handler if json data was received in the post or the data submitted was sent from the form ?
Thank You
When you send data via a Post request you will have data in your params Hash. So if there is a key there is a value, even if it's empty. So you can check for example via params[:json] if you have received something via json (assuming you call that parameter :json). The same goes for data. But then I'm not entirely sure if that's what you're asking for. Either way all data you get is handled via the params variable.
Assuming that JSON is sent via XHR call, you can make use of request.xhr? to check if the request is xhr.

ajax response for node file

so still a newb to nodeJS and back end code in general. I need some help with ajax and node. For instance I have a function that goes like this
function random(response) {
var objToJson = {...};
response.write(objToJson);
response.end();
}
if instead of writing I want to pass this json object to another function as a response of an ajax call made to it how would that be?
Thanks for you help!
Node.js allows you to easy manipulate HTTP request and response objects.
Ajax still sends a HTTP request object and the Ajax onsuccess callback manipulates a HTTP response object.
Writing an object to a response for an ajax request allows your ajax success handler to manipulate that data.
There are abstraction libraries for RPC like now
It sounds like you want to return a javascript object to work with in your client-side code. While that's not possible directly (you can't send an object directly over HTTP; you're always serializing/deserialing in some fashion), you can certainly return a JSON payload and easily convert that to an in-memory javascript object. If that's what you're doing, you should set the response content type to application/json.
response.setHeader("Content-Type", "application/json");
If you're writing "pure" javascript (no framework wrapping XmlHttpRequest), you'll need to eval() the responseText to convert it to an object. If you're using something like jQuery, it will do that work for you (assuming you set the content type as suggested above).

Resources