簡體   English   中英

Javascript jQuery跳過可選參數

[英]Javascript jQuery skipping optional params

1行JavaScript代碼

$.post('/blah', { comment_id: 1, description: ... });

出於某種原因,該調用不是作為JS調用進行的,並且根據文檔post方法允許2個其他可選參數, successdataType 我想跳過success並將dataType設置為script 我嘗試了這個,它給了我一個錯誤

$.post('/blah', { comment_id: 1, description: ... }, ,"script");

傳遞nullundefined

$.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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM