dimanche 23 octobre 2016

Ajax post not returning to page where post was sent from

I am posting multiple checkbox values via ajax to a php file which processes the data sent and updates a database. The post works as does the database updates based on the checkbox's values sent.

The problem I have is that it does not return to the calling php file where the ajax call is made from. I have to click on the previous button in the browser and refresh the browser page to see the results from the updated database.

The code for the checkboxes.

echo "<form id='assign' method ='post'  action='../../assign_engineer_post_code.php'>";
echo "<input type='checkbox' checked name='select-all' id='select_all' />Select All<br/><br/>";
echo "<p style='font-size: 10px; '>";
while($row = mysqli_fetch_assoc($res)){
    echo "<input type='checkbox' class='checkbox' name='engineers[]' value='".$row['Engineer_id']."' checked><label for='" .$row['Engineer'] ."'>" .$row['Engineer'] ."</label>"; 

        echo "&nbsp;&nbsp;&nbsp;";
        $counter++;
        if ($counter == 8){
        //echo "<br/>";
        } 
}
echo "</p>";
?>
<table><tr>
<td>
<button type="button" onclick="clear_sap_data()">Clear Data</button>
</td>
<td>
<button type="button" onclick="import_sap_data()">Import SAP Data</button> 
</td>
<td>
<!-- <input name="confirm" type="button" value="Assign Engineers" onclick="doit();" /> 
<input id="submit" type="submit" name="submit" value="Submit" onclick="submitForm()" /> -->
<input id="submit" type="submit" name="submit" value="Submit" onclick="submitForm()" />
</td>

</tr>
</table>
</form>

The script called submitForm is as follows

<script>
function submitForm() {
var form = document.assign;

var dataString = $(form).serialize();


$.ajax({
    contentType: false,
    processData: false
    type:'POST',
    url:'../../assign_engineer_post_code.php',
    data: dataString,
    success: function(data){
        window.location.reload(); // This is not jQuery but simple plain ol' JS

    }
});
return false;
}
</script>

The php file called does what is is supposed to do but it does not return to the calling page and the ajax window.location.reload() is not invoked.

Regards

Alan




Aucun commentaire:

Enregistrer un commentaire