开发者

Javascript jQuery skipping optional params

1 line of JavaScript code

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

For some reason, the call is not made as a JS call and per documentation, the 开发者_如何学JAVApost method allows for 2 more optional params, success and dataType. I would like to skip success and set dataType to script. I tried this and it gave me an error

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


Pass null or 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");


Your code is invalid Javascript. If you want to skip a parameter, you have to pass a null value instead:

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


You can pass null for the default parameter.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜