bobby
bobby

Reputation:

variable declaration in ajax

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>

Upvotes: 0

Views: 2116

Answers (2)

Gabriel Hurley
Gabriel Hurley

Reputation: 40072

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);
},

Upvotes: 0

seth
seth

Reputation: 37287

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);
    },

Upvotes: 1

Related Questions