TeddyCoder | Web Freelancer in Hochiminh City

Ajax Submit Form

HTML :

<form method="post" class="form-1" id="ajaxform" action="<?php echo APP_URL; ?>sp/mailer/index.php?<?php echo $gtime ?>" name="form1" onSubmit="return check()">

</form>

 

JS:

<script>
$(document).ready(function()
{

$("#simple-post").click(function()
{
$("#ajaxform").submit(function(e)
{
$("#simple-msg").html("<img src='loading.gif'/>");
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
$.ajax(
{
url : formURL,
type: "POST",
data : postData,
success:function(data, textStatus, jqXHR)
{
var call = $('#telClick').attr('href');
location.href = call;

},
error: function(jqXHR, textStatus, errorThrown)
{
$("#simple-msg").html('<pre><code class="prettyprint">AJAX Request Failed<br/> textStatus='+textStatus+', errorThrown='+errorThrown+'</code></pre>');
}
});
e.preventDefault(); //STOP default action
e.unbind();
});

//$("#ajaxform").submit(); //SUBMIT FORM
});

});
</script>

BACK