Codementor Events

The Javascript Submit Postback Problem

Published Jan 21, 2019
The Javascript Submit Postback Problem

So I have seen several articles and suggestions for a problem that I cannot seem to solve.

The basic setup is this, I have a PHP page that is using jquery.fileuploader (not particuarlly relevent) to upload a file to my server. My page also has a form on it that has checkbox and text search textbox that postback to its self when submit is clicked. This all works fine. The file uploader works and puts the file on my server no problems. The standard form submits back to the same page to filter and update the page based on the status of the check boxes, this works just fine.

The problem I am having is this. Once the fileuploader finishes it process, I want the page to postback to its self, in order to pass the filename accross so I can catch it with the PHP.

I have added the following at the end of the upload process script, in an attempt to submit the results (file name) collected from javascript to post back to the page:

```
document.getElementById("filterForm").submit();
```

I can confirm that a post is made but the page is never reloaded so the PHP never has the oppertunity to catch the value and reload the page.

Basically what I am trying to do is take the results of a javascript function (variable) and post it back to the same page where PHP processes the post in order to get the value from javascript to PHP. Im doing it this way mostly to get the "filename" value to PHP via a POST.

Any help or suggestions would be greatly appriciated.

Thanks,
Joshua

Discover and read more posts from Joshua
get started
post comments2Replies
Răzvan Moldovan
6 years ago

You should try AJAX or see if the jquery plugin you are using supports submitting additional data along with the files.

Joshua
6 years ago

I was wanting to set a value and submit along with the form. Was thinking like a hidden variable attached to the post. I just don’t get why I can trigger a post with .submit() and it does not reload the page but clicking on the form submit button reloads the page along with the form data being posted. Any thoughts on why that is happening. I am not using Ajax because I am trying to make this as lean as I can.