views:

44

answers:

2

Hi I need to write an ajax function to reload the content in a div of my Free marker tool page

the Div contains a question with yes or no radio buttons and when the user picks yes and click the submit button the page should reload and as I am very new to ajax I wrote something like this PLEASE LET ME KNOW IF THE FORMAT I WROTE IN CREATING A VARIABLE IS RIGHT OR WRONG AND PLEASE LET ME KNOW IF I WROTE ANY SYNTAX ERRORS THANKS

<script type="text/javascript">
function submitOptIn() {
    $('optInError').hide();
    dataString = $('#partnerOptIn').serialize();
    $.ajax({
     data: dataString,
     timeout: 30000,
     type: "POST",
     var newHtml = "<h4>Thank you</h4>
     <p>We appreciate your time to respond to our request.</p>";
     success: function(html){
      $('#optInContent').html(newHtml);
     },
     success: function(html){
      $('#optInContent').html(html);
     }, 
     error: function(){
      $('#optInError').show();
     }
    });
}
</script>
+1  A: 

Move the newHTML declaration to inside of the success function:

    success: function(html){
            var newHtml = "<h4>Thank you</h4><p>We appreciate your time to respond to our request.</p>";
            $('#optInContent').html(newHtml);
    },
seth
damn, you beat me to it by 2 seconds.
Gabriel Hurley
A: 

For one, you should declare your newHtml variable inside the success function, not before it:

success: function(html){
    var newHtml = "<h4>Thank you</h4><p>We appreciate your time to respond to our request.</p>";
    $('#optInContent').html(newHtml);
},
Gabriel Hurley