Skip to content
Advertisement

Ajax call from click event issue

Look at the HTML code below:

JavaScript

Now I want to trigger the file upload and call to ajax on the click by .upload-button.

This is how I tried it in jQuery,

JavaScript

But, this code not working for me. That mean it didn’t send the ajax request.

Hope somebody may help me out.

Advertisement

Answer

I think you’re mixing up a trigger with an event handler.
When you click the div you should trigger a click on the file input but you don’t pass a callback there.
You want to set up a change handler for the file input to make an ajax request when the file is selected with a change event handler.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement