Your function is not visible globally, as indicated in Pointy. But you also load the script and call the function defined by the ready() function. I think it is possible that ready() can be called when your script calls foobar() , which will generate the same error. I would recommend that you set the global value in the script, and then use this variable in the ready() function.
Set the value in the script:
<script src='http://foobar.com/static/js/main.js' type='text/javascript'></script> <script type='text/javascript'>var bar = '123456'</script>
Then you can use it in the ready() function.
$(document).ready(function() { $.ajax({ url: "/site/foo/", data: {'foo':bar}, dataType: "jsonp", crossdomain: !0, success: function (data) { alert(data); }, error: function () { } }); });
If you want to define a function so that it can be used again, you can call it in ready() , but make sure that you set the global variable bar to what you want.
window.foobar = function() { $.ajax({ url: "/site/foo/", data: {'foo':bar}, dataType: "jsonp", crossdomain: !0, success: function (data) { alert(data); }, error: function () { } }); } $(document).ready(function() { foobar();
Steve O'Connor Dec 19 '11 at 10:48 2011-12-19 22:48
source share