javascript - require_once() or AJAX causing php script to run twice
Get the solution ↓↓↓Solution:
May be this? Why that line is there on your config file?
header("Location: " . $_SERVER['REQUEST_URI']);
Answer
Solution:
It looks like config.php is replacing the value of $_SESSION['step4filepath'] with $_POST['step4filepath'], rather than leaving it as $path_of_uploaded_file.
EDIT
As mentioned elsewhere, header() will be causing a reload. My answer is irrelevant as config.php is called before the var is set.
Answer
Solution:
Solution 1
Replace
$(document).on('click', '#uploadbutton', function(e) {
To
$(document).off('click').on('click', '#uploadbutton', function(e) {
Solution 2: See below sample code
$(document).on("click", "#someID", function(e) {
$(this).attr("disabled","disabled");
// Disabling the input stops the event from firing multiple times.
var targetObj = $(this);
// targetObj can be used within the $.POST function, not $(this)
var myVariable = "Hello world";
$.post("/DoSomethingAJAXY.php", { variable1: myVariable },
function(data, status){
if (status == "success") {
// Do something
}
$(targetObj).removeAttr("disabled");
// Re-enable the event input trigger
});
}
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.