I'm getting the following result through ajax.
row=Shimla|1|http://vinspro.org/travel/ind/
I wanna http://vinspro.org/travel/ind/ from it. I have used find and split function but it is not working . please let me know how I can get it?
var result=$(row).split('|'); alert(result);
chrome showing the following error
Uncaught Error: Syntax error, unrecognized expression: Shimla|1|http://vinspro.org/travel/ind/
The split() method splits a string into an array of substrings. The split() method returns the new array. The split() method does not change the original string. If (" ") is used as separator, the string is split between words.
var data = $('#date'). text(); var arr = data. split('/'); $("#date"). html("<span>"+arr[0] + "</span></br>" + arr[1]+"/"+arr[2]);
The explode function is utilized to "Split a string into pieces of elements to form an array". The explode function in PHP enables us to break a string into smaller content with a break. This break is known as the delimiter.
If you want to explode or split a string from a certain character or separator you can use the JavaScript split() method. The following example will show you how to split a string at each blank space. The returned value will be an array, containing the splitted values.
The split
method will create an array. So you need to access the third element in your case..
(arrays are 0-indexed) You need to access result[2]
to get the url
var result = $(row).text().split('|'); alert( result[2] );
You do not give us enough information to know what row
is, exactly.. So depending on how you acquire the variable row
you might need to do one of the following.
row
is a string then row.split('|');
$(row).text().split('|');
input
element then $(row).val().split('|');
Split creates an array . You can access the individual values by using a index.
var result=$(row).val().split('|')[2] alert(result);
OR
var result=$(row).val().split('|'); alert(result[2]);
If it's input element then you need to use $(row).val()
to get the value..
Otherwise you would need to use $(row).text()
or $(row).html()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With