I am new to both Ajax and Php. The code below is a form.
<div>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data">
<label>Username:</label><input type="text" value="" size="30" name="username"/> <br/><br/>
<label>Chart type:</label><input type="radio" name="chart" value="PI">PI
<input type="radio" name="chart" value="BAR">BAR
<input type="radio" name="chart" value="LINE">LINE <br/><br/>
<label for="file">Filename:</label>
<input type="file" name="file" id="file"> <br/><br/>
<input type="submit" name="submit" value="Submit" />
</form>
</div>
I need to hide the above form and call a Php function when the submit button is clicked. How do I do it using Ajax?
Its a basic thing you can get it easily when you go through google itself. Please search and if you didnt get post it here.
Anyhow, you can go by the following way using jquery ajax,
$.ajax({
type: "POST",
url: "phpFunction.php",
secureuri:false,
fileElementId:'file',
dataType: 'json',
success: function(response){
if(response)
{
//hide your form
} else {
//show error on your form.
}
}
});
In php file you have to receive and upload the file and return the status to success callback function..
Gothrough the following url, File Upload Using Ajax