Philip Posted July 19, 2007 Share Posted July 19, 2007 Hey guys, I'm not sure if it's because I'm using some AJAX, but I'll go ahead and post it here. I've been having some problems slitting a string (the response from my php script). My php page will echo a string like "1|0|40|titlehere". Then I have JS split the string by "|". However, when I try to print out one of the array parts it just comes back as "1,0,40,titlehere" var response1 = request.responseText.toString(); var response = response1.split("|"); var type = response[0]; var fail = response[1]; var title_id = response[2]; var title_name = response[3]; var fail_error = response[4]; var updatestatus = document.getElementById("update-status"); replaceText(updatestatus, response[2]); The code above should show a "0" for a string like "1|0|40|titlehere". Instead it shows "1,0,40,titlehere". I've tried just about everything I could do, adding split directly onto the response text, adding toString() (to make it reads it correctly), splitting again for the commas (which just gives js a loop, and it never finishes loading) Any ideas? Quote Link to comment Share on other sites More sharing options...
RichardRotterdam Posted July 19, 2007 Share Posted July 19, 2007 if request.responseText.toString() truly has a string value like "1|0|40|titlehere" then you are splitting the the string correctly are you sure the request.responseText is has that value try to alert it Quote Link to comment Share on other sites More sharing options...
Philip Posted July 20, 2007 Author Share Posted July 20, 2007 Yeah, it alerts a statement like above (just different variables inside each section) Edit: I found the problem. I had originally put in a [1] at the end, but it got deleted (I think when I was testing to see if it was getting the string correctly) so that's why it was showing the whole array. I need more sleep. Haha Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.