Skip to content
Advertisement

when i click add, data is saved and also shown on the same page through ajax but if i want to sort data, button is not working

im adding data in the db and at the same time it is shown to the same page through ajax when add button is clicked. now i want to show data in ascending order adn as well as in descending order also. data is shown on add click but when i clicked ascending button, data is not shown. same is the thing with descending button.

add.php file

JavaScript

The javascript functions

JavaScript

data.php file

JavaScript

Advertisement

Answer

You can modify each function to send a new parameter – I chose task but that it not important. The value is changed for each request type as you will see in the javascript. The PHP code can look for and then fork logic based upon this single POST variable.

FYI: Blindly extracting variables in PHP using extract opens the door to various attacks – only use that with caution once you have sanitised the POST array ~ perhaps using filter_input_array as a start and a whitelist of acceptable names/types.

JavaScript

Data.php

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