Link to home
Start Free TrialLog in
Avatar of Eric Zwar
Eric ZwarFlag for Australia

asked on

JavaScript/jQuery array logic not working

I have a couple of PHP modules that include JS and jQuery logic.  One is chat.php and the other is fetch_user.php.  chat.php does a jQuery ajax call to fetch-user.php  and fetch_user.php returns an HTML table to chat.php which is then inserted into chat.php's DOM.  All this works perfectly.

In the data returned from fetch_user.php there is an HTML button which has some attribute data which the ajax  'success' function has access to and I can extract this data OK.

My issue is that I have a JS array which as far as I am aware has global JS access.  I want to first empty the existing data in that array (which is named logged_in_array) and the add the extracted attribute data to that array.  In my code the logged_in_array.length = 0 does not empty the array, nor does the logged_in_array.push work.

So my specific issues are that the array is not being emptied nor is the attribute datum being added to the array.

I will attach extracts of the code:

demo-code.html
Avatar of leakim971
leakim971
Flag of Guadeloupe image

to empty just set it value to an empty one :
logged_in_array = [];

Open in new window

or :
logged_in_array = new Array();

Open in new window

Avatar of Eric Zwar

ASKER

My understanding is that I can't do that as the array needs to be visible to other JS functions and if I use suggestion 1: it will create a new array not globally visible within JS.
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I tried that but it does not empty the array and the array push still does not work as when I call fetch_user again it is still sending the original array data



demo-code.html
Don't know why but it is now working??

Sorry to have bothered you.
no worry :)