Firstly let me preface this by saying I would never WANT to do this, nor do I intend to do this, I simply need to know if it is possible.
Considering that you can place “javascript:myFunction();” in a link’s href attribute, is it possible to specify “javascript:myFunction();” as the url parameter in jQuery’s $.ajax function?
Again, I know this would be counterintuitive and a pointless exercise for any production code. I am simply interested in whether it could theoretically be done.
No it does not work.
The
javascript:myFunction()is something of a hack URL that you can put as thehrefof an anchor to link to a JS function.$.ajaxwants to make an HTTP request and will attempt to, with whatever URL you provide. In the case of ajavascript:*URL, it will do nothing useful.