How to get 100 characters from wikipedia api

jquery

#1

Hello!
I want to retrieve 100 characters from Wikipedia API
searching i got all the text content but i just need 100 characters
here is my Code

<div id="article"></div>

<script type="text/javascript">

    
    $(document).ready(function(){

	$.ajax({
	    type: "GET",
	    url: "http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text&section=0&page=Jimi_Hendrix&callback=?",
	    contentType: "application/json; charset=utf-8",
	    async: false,
	    dataType: "json",
	    success: function (data, textStatus, jqXHR) {
	    
		var markup = data.parse.text["*"];
		var i = $('<div></div>').html(markup);
		
		// remove links as they will not work
		i.find('a').each(function() { $(this).replaceWith($(this).html()); });
		
		// remove any references
		i.find('sup').remove();
		
		// remove cite error
		i.find('.mw-ext-cite-error').remove();
		
		$('#article').html($(i).find('p'));
			
		
	    },
	    error: function (errorMessage) {
	    }
	});    
    
    });
    
	
    
</script>

#2

can any one help me in this? please,


#3

How / where are you determining that you’re getting the text content? In the <div></div> / a elements?


#4

@Mittineague Yes, In

<div id="article"></div>

#5

And currently it gets everything starting with
<div class=\"mw-parser-output\">
and ending with the closing </div> ?

There’s an awful lot of HTML in the content. You want to not truncate in a way that breaks a tag or causes it to not be well-formed. Can you limit the value to text content only with no HTML tags? Once you get that far it should be easy enough to use a string function to get something like:
“blah, blah blah 100 characters ‘… ellipsis here’”


#6

Got the answer as simple
by changing

('#article').html($(i).find('p'));

With

$('#article').html($(i).find('p').text().slice(0, 100));