-4

我在以下代码中不断收到错误意外令牌“)” 。谁能告诉我我的代码有什么问题?

function postFrom()
{
 /* contactform */
$.post('/contact_owner/send/', { 

customer_name: $('[name="customer_name"]').val(),
customer_phone: $('[name="customer_phone"]').val(),
customer_email: $('[name="customer_email"]').val(),

customer_message: $('[name="customer_message"]').val() +' \n-Adress: '+ $('[name="customer_address"]').val() +' -Postnummer: '+ $('[name="customer_zipcode"]').val() +' -Ort: '+ $('[name="customer_city"]').val() + ' -Markisvävar: '+ final,

subject:$('[name="customer_name"]').val() +' - '+ $('[name="sub"]').val()  },     function(data){
  if (data) {
    $('#status_notice').css('color', 'red');
    $('#status_notice').html(data);
  } else {
    $('#status_notice').css('color', 'green');
    $('#status_notice').html('Ditt meddelande skickades.');
    $('[name="customer_name"]').val('');
    $('[name="customer_phone"]').val('');
    $('[name="customer_email"]').val('');
    $('[name="customer_address"]').val('');
    $('[name="customer_zipcode"]').val('');
    $('[name="customer_city"]').val('');
    $('[name="customer_message"]').val('');
  $('input[type=checkbox]').each(function() 
  { 
    this.checked = false; 
  }); 

}
});
event.preventDefault();
});
});                                                       

/* contactform END */

}//end function
4

4 回答 4

5

您正在尝试使用}):来关闭该功能(您只需要使用}),而且您还有一些杂散的右括号。

尝试这个:

function postFrom()
{
 /* contactform */
$.post('/contact_owner/send/', { 

  customer_name: $('[name="customer_name"]').val(),
  customer_phone: $('[name="customer_phone"]').val(),
  customer_email: $('[name="customer_email"]').val(),

  customer_message: $('[name="customer_message"]').val() +' \n-Adress: '+ $('[name="customer_address"]').val() +' -Postnummer: '+ $('[name="customer_zipcode"]').val() +' -Ort: '+ $('[name="customer_city"]').val() + ' -Markisvävar: '+ final,

  subject:$('[name="customer_name"]').val() +' - '+ $('[name="sub"]').val()  },     function(data){
  if (data) {
    $('#status_notice').css('color', 'red');
    $('#status_notice').html(data);
  } else {
    $('#status_notice').css('color', 'green');
    $('#status_notice').html('Ditt meddelande skickades.');
    $('[name="customer_name"]').val('');
    $('[name="customer_phone"]').val('');
    $('[name="customer_email"]').val('');
    $('[name="customer_address"]').val('');
    $('[name="customer_zipcode"]').val('');
    $('[name="customer_city"]').val('');
    $('[name="customer_message"]').val('');
    $('input[type=checkbox]').each(function() 
  { 
    this.checked = false; 
}); 

}
});
event.preventDefault();
}
于 2013-04-09T22:29:08.313 回答
4

格式化代码后,最后两});行似乎是多余的,应该删除。

格式化后:

function postFrom()
{
    /* contactform */
    $.post('/contact_owner/send/', {
        customer_name: $('[name="customer_name"]').val(),
        customer_phone: $('[name="customer_phone"]').val(),
        customer_email: $('[name="customer_email"]').val(),
        customer_message: $('[name="customer_message"]').val() + ' \n-Adress: ' + $('[name="customer_address"]').val() + ' -Postnummer: ' + $('[name="customer_zipcode"]').val() + ' -Ort: ' + $('[name="customer_city"]').val() + ' -Markisvävar: ' + final,
        subject: $('[name="customer_name"]').val() + ' - ' + $('[name="sub"]').val()}, function(data) {
        if (data) {
            $('#status_notice').css('color', 'red');
            $('#status_notice').html(data);
        } else {
            $('#status_notice').css('color', 'green');
            $('#status_notice').html('Ditt meddelande skickades.');
            $('[name="customer_name"]').val('');
            $('[name="customer_phone"]').val('');
            $('[name="customer_email"]').val('');
            $('[name="customer_address"]').val('');
            $('[name="customer_zipcode"]').val('');
            $('[name="customer_city"]').val('');
            $('[name="customer_message"]').val('');
            $('input[type=checkbox]').each(function()
            {
                this.checked = false;
            });
        }
    });
    event.preventDefault();
    /* contactform END */

}
于 2013-04-09T22:29:25.460 回答
3

打字错误,多余的括号

});
event.preventDefault();
}); // delete it
}); // delete it
于 2013-04-09T22:31:07.197 回答
2

更好的缩进可能会对你有很大帮助,但我认为 }); 假设 event.PreventDefault 应该在函数的末尾,则不需要第 (33、34) 行。

于 2013-04-09T22:32:44.650 回答