I have homepage.asp (old legacy code) with a div like this:
<div id="poll"></div>
I am loading another page with a self contained form (it submits to itself) in to this div like this:
$.get('Poll/poll.asp', function(data) {
$('#poll').html(data);}
);
The form on poll.asp looks basically like this :
<form id="formPoll" onsubmit="return false">
<table id="pollp" cellpadding="2" cellspacing="0"><tr>
<td colspan="2" class="PollQuestion">Poll question here</td>
</tr>
<tr>
<td width="20"><Input type="Radio" name="SelOPT" value="1" /></td>
<td width="230">Option 1</td>
</tr>
<tr>
<td width="20"><Input type="Radio" name="SelOPT" value="2" /></td>
<td width="230">Option 2</td>
</tr>
<tr><td colspan="2">
<input id="pollSubmit" type="submit" value=" Cast Vote " />
</td></tr></table>
<input type="Hidden" name="mode" value="vote" />
</form>
I am trying to submit the form without refreshing the page, but I need the page loaded in the div to reload to show the results of the form submission. On homepage.asp I have a script like this:
$(function() {
//hang on event of form with id=formPoll
$("#formPoll").submit(function(e) {
//prevent Default functionality
e.preventDefault();
//do your own request an handle the results
$.ajax({
url: 'Poll/poll.asp',
type: 'post',
dataType: 'json',
data: $("#formPoll").serialize(),
success: function(data) {
//if(data.success == true){ // if true (1)
//$("#poll").load("#poll > *");
$('#poll').html(data);
}
}
});
});
});
homepage.asp does not refresh on submit but it only submits the form data every other time the button is clicked and I have to manually refresh the page to reload the results. I think I have read every "refresh or reload div after submit" question on here with no luck. Any ideas would be appreciated. You can see a couple of the things I have tried commented out under the success function.