Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  65] [ 3]  / answers: 1 / hits: 41181  / 10 Years ago, wed, april 9, 2014, 12:00:00

I want to submit this form via jquery ajax, this is what I have made and it is not working. i.e. Form is submitting with page refresh and I am not seeing the response i.e. printing array on the same page.



HTML



  <link rel='stylesheet' type='text/css' href='css/pepper-grinder/jquery-ui-1.10.4.custom.css' />
<script type='text/javascript' src='js/jquery-1.10.2.js' ></script>
<script type='text/javascript' src='js/jquery-ui-1.10.4.custom.min.js' ></script>
<form id=form1 method=get action=submit.php >
<label>Name of Organization</label>
<input type=text name=OrgName id=OrgName class=textfield>
<label>Address of Organization</label>
<input type=text name=OrgAddress id=OrgAddress class=textfield>
<input type=submit value=Register Organization>
</form>
<div id=response>ads</div>

<script>
$document.ready(function(){
$(#form1).click((function(event){
event.preventDefault();

$.ajax({
url:'submit.php',
type:'GET',
data:$(this).serialize(),
success:function(result){
$(#response).text(result);

}

});
});
});
</script>


PHP (submit.php)



<?php
print_r($_GET);
?>

More From » php

 Answers
98

Use this - there have been a few syntax errors and the event has to be submit



 $(function(){
$(#form1).submit(function(event){
event.preventDefault();

$.ajax({
url:'submit.php',
type:'GET',
data:$(this).serialize(),
success:function(result){
$(#response).text(result);

}

});
});
});

[#71546] Monday, April 7, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arthur

Total Points: 729
Total Questions: 107
Total Answers: 109

Location: China
Member since Mon, Aug 22, 2022
2 Years ago
;