How to upload a file using Ajax request in rails 2.3 - ajax

I have a rails 2.3 application.
I am using Ajax request to submit the form content. In my form, I have a provision to upload files.
Issue with the form is, if I added a file to the form and submitted the form content, I am getting an error "Error: NS_ERROR_XPC_BAD_OP_ON_WN_PROTO: Illegal operation on WrappedNative prototype object Source" in "jquery-1.4.4.min.js" file and the form is submitting normally without using ajax request. But, the form is submitting form content using Ajax when there is no file selected to upload.
Can anyone please tell me how to upload file using Ajax request.

I found a solution for my above mentioned requirement at the following url. Hope it may help some one.
http://priyanka-railsdeveloper.blogspot.in/2011/11/allow-ajax-upload.html

Related

Django - download file without reloading the page

The flow looks like that:
user is filling the form
form is passed to the server by ajax
form is saved to db, then the pdf with the form data is created and saved in the app folder (probably a bad move here...)
ajax success causes the page to append a button 'Download' with value equal to current pdf's name so button 'Download' appears to the user
If user presses the button the very pdf that was just saved is gonna download.
Refreshing the page makes the button disappear.
I've got stuck on point 5. I have created another ajax (to avoid reloading the page) bound to the Download button. It correctly asks the server to look for the file, creates a django File object: pdf_file = File(open(file_path, 'rb'))
and creates a HttpResponse with file, and content_type='application/pdf' or 'application/download'.
response['Content-Disposition'] is attachment.
Then the ajax returns response - only it does not. Server raises no error but ajax error function is called.
I've read that downloading with ajax is not possible. Could you help me a bit to get it straight? If above snippets are not clear, I shall provide more code.
Python 3.5, Django 1.10
Do like
window.location.href = "/url/to/downloadfile/"
in javascript after success of posting form. OR
#html
<button onclick="myfiledownload()">Download</download>
#javascript
function myfiledownload(){
window.location.href = "/url/to/downloadfile/"
}
Instead of using ajax to download the file bind the button to a download link where the file may be hosted
https://www.mywebsite/download/?fileid=3247023
You should at least seperate your file in a media root
Note: in production you will have to use a cdn to host your static files

Is there anyway to submit form which will have also upload multiple file using ajax in asp.net mvc 3/4?

I want to submit form using ajax.but the problem is that ,i found ajax doesn't support file upload while we submit form.Is there any other way we can do it using ajax because i don't want to refresh page using normal form submit.Please help any suggestion will be very helpful for me.
thanks in advance
You can do this in several ways:
First:
Use canvas
How to save a HTML5 Canvas as Image on a server
Second:
Use some js library like:
http://blueimp.github.io/jQuery-File-Upload/ or
https://github.com/LPology/Simple-Ajax-Uploader
Third:
Use html5 FormData
How to upload a file using jQuery.ajax and FormData

Submitting image directly through AJAX?

After looking around at some stuff, I've found that you can submit a form to a frame using the "target" attribute.
That works for me, except, it submits the WHOLE form.
I have a form. It's all submitted to a PHP file with AJAX POST.
I want to include an image upload in this form.
Is there any way to directly upload the image THROUGH AJAX to the same PHP file, or do I have to put a form within a form (because I think that that's rather sloppy).
Thanks a bunch!
NO jQuery. Straightforward DOM, please.

Usage of Ajax form

I am an average newbie to CakePHP. While reading cookbook found Ajax form and its submission. But it lacks more details.
What are the main difference between ajax form and a normal form or What are the more specific cases we need to use Ajax form over normal form?
An example will be appreciated
Thanks....
A properly implemented Ajax form is exactly the same as a regular form, except that if JavaScript is enabled a submit handler will be bound to it that will prevent the normal submission of the form and send the data using the XMLHttpRequest object. The response will then be processed by JavaScript in the current page instead of by loading an entirely new page.
This isn't necessarily a CakePHP question, it's understanding what AJAX is.
AJAX in layman's terms is basically submitting data to a website without reloading the current page. If this is the sort of feature you want, you'll need to look into the RequestHandler component and the JsHelper in the CakePHP book for the version you are using.

Post Form data with also some input files to Web Api

Is there any updated example to upload files with a form with fields and file inputs that post to a mvc4 webapi controller?
I am trying to post with Jquery axax to a asp.net mvc4 ApiController.
I used the Jquery file Upload plugin for the client side part.
As the webapi seems not to support multiform data I tried to solve with this configuration formatter but still looking for a better solution
See: http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2
(Scroll down to "Supporting Multipart MIME Data")
I have not actually tried this with the jQuery plugin, only with plain HTML forms.

Resources