Reputation: 10137
I don't know exactly why or how this is happening (though if someone has any information as to why or how, it would be greatly appreciated if it was posted here).
My function is supposed to just make a simple ajax call to a specified file, which is then supposed to process that call.
function processLog(process, ajaxData, url) {
switch(process) {
case 'send':
$.post(url, {clientData : ajaxData, type : process},
function(data){
writeLog(data);
}
);
break;
case 'retrieve':
$.post(url, {clientData : ajaxData, type : process},
function(data){
retrieveChatroomData(data);
}
);
break;
}
}
Basically, the function receives three params: process, ajaxData, url. The process is supposed to be either of the value send or retrieve. If it's value is send, it simply writes out the data to the log. If it's retrieve, it retrieves the entire data sent before in the window and posts it for all to see. If anyone needs to see anymore code, I'll happily post, just let me know :).
The main issue is that when I click the following button:
<input type="button" value="send" id="chatroom_send" onclick="processLog('send', $('textarea.chatroom_textarea').value, 'chatroom.base.php');" />
I get a "processLog" is undefined error in the Firebug console.
What am I doing wrong?
Upvotes: 0
Views: 1292
Reputation: 129001
Your code may look like this:
$(function() {
function processLog(/* ... */) {
// ...
}
});
Wrapping code in a ready handler like that is needed for some things, but it will pull processLog
out of the global scope. Either move it out of the ready handler or add this somewhere in the ready handler to export it to the global scope:
window.processLog=processLog;
Upvotes: 3