-
help with ajax
Hi there, i have a webpage which takes in user details to store them into a database. i have 2 files html and php. the html file takes the input and sends it to the php file. when the html sends data to php the browser changes to the php file however i would like to stop this happening. when the input is not correct and the submit button is clicked on i would like to stop the html sending data to the php and to stay as it is with the incorrect data.
i have been told that AJAX is the solution to this problem as AJAZ can check the data in the background without changing the webpage. i am totaly new to AJAX and was hoping someone would please give me some guidance.
e.g.
<form action="http://localhost/PATIENT/filename.php" method="post" name="name" id= "name" onsubmit"error checks">
<input name="abc" type="text"/>
<input type="text" name="xxx"/>
</form>
<?php
database connection....
$abc = $_POST['abc'];
$xxx = $_POST['xxx'];
?>
-
if u r looking for a quick and simple solution, u can stay away from ajax and simply redirect from the php page to an error "section" into ur html page, or maybe a third error page ...
a common method also is to include all in the same page, and handle the request (differentiate between the case of requesting data or posting them) by a php code like this :
Code:
if(isset($_POST['var']))
{
// ....
}
else
{
// web input form
}
if you still want to use ajax, u have to read a bit about how it's working and how to implement it, usually in your case u need another third php page ... take a look here it's a good learning tool with many good examples:
http://www.w3schools.com/ajax/default.asp