linkedin apply button callback and jquery (or ext callbacks in general)

我怕爱的太早我们不能终老 提交于 2019-12-25 01:53:25

问题


I'm adding the linkedin apply button to a site and will use the callback to track applications

https://developer.linkedin.com/apply-processing-applications

Linkedin docs/example:

<script type="text/javascript">
function myOnclickFunction(r) {
        alert("click");
        console.log(r);
        // do something here
}

function myOnsucesssFunction(r) {
        alert("success");
        console.log(r);
        // do something else here
}
</script>

<script type="IN/Apply" 
      data-email="apply-test@linkedin.com" 
      data-companyId="1337" 
      data-jobTitle="Chief Cat Herder" 
      data-onclick="myOnclickFunction"
      data-onsuccess="myOnsuccessFunction">
</script>

I'm able to do this with conventional javascript, but would like to try this as my first jquery project, but have no idea how to start.

Could someone give me a start on how I can go from here (just give an outline - not expecting to have it written for me!)

$(document).ready(function() {
   // do stuff when DOM is ready
 });

to adding a function within there that linkedin can call, or even a link to similar examples, as all my searching with the keyword callback seem to reference callbacks generated by other jquery functions.

I will need to extract some json data, and do an ajax call. Thanks, Kevin


回答1:


No, if you put something inside of $(document).ready() it is placed in an anonymous function and is outside of the global scope.

With something like that, you should probably put the function that is going to be called in the global scope. Since it isn't getting called on load anyway, it doesn't need to be inside $(document).ready().

Also, be careful with $(document).ready(), if not used properly it can slow down the page load!

Good luck with jQuery, the only downside is that you'll get addicted!



来源:https://stackoverflow.com/questions/16466789/linkedin-apply-button-callback-and-jquery-or-ext-callbacks-in-general

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!