An error occurred while receiving an unaccepted TypeError: the string is not a function

I am using this code here for a webpage from which I am cheating:

$(function() { console.log('Here'); $.ajax({ type: 'POST', url: 'http://api.bf3stats.com/pc/playerlist/', data: { players: ['xxx', 'xxxx', 'x'] }, success: function(data) { loadData(data, 'x', 'f'); } }) }) function loadData(data, uname, $) { $('#fWins').text("135"); } 

But as soon as it gets into the loadData function, I get an error:

 Error: Uncaught TypeError: string is not a function 

I absolutely do not know why this causes me so many problems. Thanks in advance!

Thanks, the problem is that I used $, I often do not use jQuery, only when I need cross-browser compatibility. Thanks for that, will mark "Answer" when the timer is up

+4
source share
3 answers

This is because you use $ as the parameter name for the last parameter in loadData. This means that your function will use the string "f" that you pass to the function when it sees $ on $('#fWins').text("135"); instead of using jQuery, so it essentially does this: "f"('#fWins').text("135"); To fix this, change:

 function loadData(data, uname, $) { 

to something like

 function loadData(data, uname, lastParam) { 
+2
source

Try the following:

 $(function () { console.log('Here'); $.ajax({ type: 'POST', url: 'http://api.bf3stats.com/pc/playerlist/', data: { players: ['xxx', 'xxxx', 'x'] }, success: function (data) { loadData(data, 'x', 'f'); } }); }); function loadData(data, uname, param) { console.log('Here too..'); $('#fWins').text("135"); } 

FIDDLE (in the console you will get both here and Here too .. , no errors)

+1
source

$ tries to pass this variable as a function, so if you have a function declared with the passed string, it will run it

any reason you want $ there?

0
source

All Articles