Search code examples
phpajaxsymfonyserver-sidedropzone.js

ajax call to php function without changing url


I am working with Symfony2 and I am using Dropzone.js with the bundle OneUploader to upload several images at a time. Dropzone.js has the option of deleting an image that has been selected to upload, but the problem is that when I click on 'Remove' the image is only removed on the client side, not on the server. So what I need is to make an ajax call in mi dropzone.js to a function in my php that deletes the file from the server. The question is: how can I make that call in order that the url is not changed? I am using this one but it is not working, because the url is changing:

$.ajax({
          url: 'delete.php',
          method:'POST',
          data: {name: file.name}
        });

Thanks in advance.


Solution

  • Finally I was doing something wrong... I was making the ajax call in a .js file, so I could not use the path form in the url in the ajax call (twig language). So I have solved it making the ajax call in a .html.twig file and using a path in the url, that calls a routing, and it calls an action in a Controller that makes the deletion.

    By the way, thanks for your help!