Reputation: 1990
I am trying to use a javascript function defined outside of the $(document).ready(function(){}); as the callback for a $.get() request. However, firebug shows:
ReferenceError: temp is not defined
$.get('twitter.php', function(data){temp(data)});
Here's the relevant code:
<script src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="txt/javascript">
function temp(data){
alert(data);
}
</script>
<script>
$(document).ready(function() {
$.get('twitter.php', function(data){temp(data)});
});
</script>
twitter.php
does return data.
Upvotes: 4
Views: 1022
Reputation: 21
put
function temp(data){
alert(data);
}
above
$(document).ready(function(){
});
Upvotes: 2
Reputation: 8006
You have your script type set to 'txt/javascript'
, if I'm not mistaen, it should be 'text/javascript'
, also you need a semicolon after your function.
<script type="text/javascript">
function temp(data){
alert(data);
};
</script>
Upvotes: 1
Reputation: 82297
You have a small syntax error which causes the script to be invalid, type="txt/javascript"
should be:
<script type="text/javascript">
function temp(data){
alert(data);
}
</script>
Upvotes: 1