Jump to content

[SOLVED] split() issue


Philip

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/60829-solved-split-issue/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/60829-solved-split-issue/#findComment-302979
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.