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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.