[英]Javascript jQuery skipping optional params
1行JavaScript代碼
$.post('/blah', { comment_id: 1, description: ... });
出於某種原因,該調用不是作為JS調用進行的,並且根據文檔 , post
方法允許2個其他可選參數, success
和dataType
。 我想跳過success
並將dataType
設置為script
。 我嘗試了這個,它給了我一個錯誤
$.post('/blah', { comment_id: 1, description: ... }, ,"script");
傳遞null
或undefined
:
$.post('/blah', { comment_id: 1, description: ... }, null,"script");
// use void for undefined (because undefined can be reassigned)...
$.post('/blah', { comment_id: 1, description: ... }, void 0,"script");
您的代碼是無效的Javascript。 如果要跳過參數,則必須傳遞一個null
值:
$.post('/blah', { comment_id: 1, description: 'Blah' }, null, "script");
您可以為默認參數傳遞null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.