Eric Zwar
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
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
demo-code.html
ASKER
Don't know why but it is now working??
Sorry to have bothered you.
Sorry to have bothered you.
no worry :)
Open in new window
or :Open in new window