Skip to content
Advertisement

How to set null image file after ajax success in PHP?

I am working on ajax and PHP. When I click on the post button the message value removes by $(“#message”).val(“”); after ajax success (data inserted into the database by PHP and ajax ) but the file(browse ), the image doesn’t remove after success. The file should be empty after AJAX success and the ajax code is not run if I leave the image. I want to leave an image and the message should be inserted without an image and with the image is working.

JavaScript

property = property[0]; if(property){//you have to check if the files exists or it will fail trying to access properties from an undefined object

JavaScript

The post button doesn’t work when I leave the image file. but when I leave the text blank and select the image from the computer then the post button works. I want the post button should be work when I leave the browse file. And After ajax success, the file browse should be empty.

JavaScript

I am using js to show image preview.

JavaScript

The image preview should be clear or remove after ajax success and post button should be work when i leave image to browse .

Advertisement

Answer

The file input should reset however you need to remove the preview image like:

JavaScript

If the file input is not resetting try to add $("#photo").val(""); inside the success function.

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