filmov
tv
AJAX - Comment Box with [ Javascript jQuery JSON PHP MySQL ] - Step by Step How to Guide - Part 13

Показать описание
In this tutorial we do some server side validation about the data which has been sent back.
Important is that we only allow a post request to access this file data. So we check to see if a post request has been sent back. If not then we simply redirect the user back to the home page by using the header function in php.
Within the callback function of ajax, we have sent back the task=comment_insert. We will use this information to validate if this was a post request.
PHP provides us with the isset function which checks to see if a variable is actually set and available to be used. If this $_POST['task'] is set then we can check to see if the task == to comment_insert. If yes, then we will proceed, if not then we dont do anything at all as we didnt send this information back.
As we havent yet made the database and tables, we simply make a object of the information needed and send it back in JSON for. This basically is a string representation of a array or object, which can then be transmitted over the web, to be decoded back in to an object on the other side. Its also as way for different programming languages to communicate with another using the same standards.
With the information now in object form we can insert all of this data into the html which we will insert into the comment list.
Important is that we only allow a post request to access this file data. So we check to see if a post request has been sent back. If not then we simply redirect the user back to the home page by using the header function in php.
Within the callback function of ajax, we have sent back the task=comment_insert. We will use this information to validate if this was a post request.
PHP provides us with the isset function which checks to see if a variable is actually set and available to be used. If this $_POST['task'] is set then we can check to see if the task == to comment_insert. If yes, then we will proceed, if not then we dont do anything at all as we didnt send this information back.
As we havent yet made the database and tables, we simply make a object of the information needed and send it back in JSON for. This basically is a string representation of a array or object, which can then be transmitted over the web, to be decoded back in to an object on the other side. Its also as way for different programming languages to communicate with another using the same standards.
With the information now in object form we can insert all of this data into the html which we will insert into the comment list.
Комментарии