2013-05-08 64 views
0

使用AJAX將表單值傳遞到PHP頁面。一旦通過值,我將清除表單中INPUT字段的值。它工作正常,但是當我清除輸入:日期值頁面得到刷新!頁面在日期刷新重置

$('#form1').submit(function(){ 
    var formdata = $(this).serialize(); 
    $.ajax({ 
     type:'POST', 
     url:'certification.php', 
     data:formdata 
    }); 
    $(this).find('input:text').val(''); 
    $(this).find('input:file').val(''); 
    $(this).find('input:date').val(''); **On adding this line page gets Refreshed.** 
    return false; 

}); 
+1

替換此: '$(本).find( '輸入:日期')VAL( '')。 ' 這樣: '$(this).find('input [type =「date」]')。val('');' 並重試。 – 2013-05-08 04:31:43

+0

很酷,這工作正常。 – sakthi 2013-05-08 04:37:42

回答

1

jquery不支持該選擇器。

所以你越來越。

Uncaught Error: Syntax error, unrecognized expression: unsupported pseudo: date 

你的代碼應該是這樣的:

$('#form1').submit(function(e){ 
    e.preventDefault(); //this will prevent default action even if there is uncaught exeption. 
    var formdata = $(this).serialize(); 
    $.ajax({ 
     type:'POST', 
     url:'certification.php', 
     data:formdata 
    }); 
    $(this).find('input:text').val(''); 
    $(this).find('input:file').val(''); 
    $(this).find('input[type="date"]').val(''); 

}); 

http://jsfiddle.net/bz3s6/

+0

嗯,我得到那個錯誤! – sakthi 2013-05-08 04:36:27