How to use slice inside jason and ajax | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use slice inside jason and ajax

I'm trying to use slice to delete first 3 characters of string inside json. $(document).ready(function() { $.ajaxSetup({ cache: false }); setInterval(function() { $.getJSON("IOCounter.html", function(data) { $('#testTime').text(htmlDecode(slice(3(data.testTime)))); }); }, 1000); }); </script> <html> <body> <p id="testTime"></p> </body> </html> <!-- end snippet --> So I'm trying to write the content of testTime inside p id=testTime, but I need to write it without first 3 characters. When I try to use slice, like it's shown in the exapmle, it doesnt work. data.testTime is a string. Any Ideas?

21st Aug 2020, 8:23 AM
Stas Fe
Stas Fe - avatar
1 Answer
+ 1
Try something like this instead: $('#testTime').text(htmlDecode(data.testTime.slice(3))); Here is an example to show how it chops off the first 3 letters: "helloworld".slice(3) That evaluates to: "loworld" Also, I don't know what your htmlDecode is for. Your testTime probably doesn't contain HTML tags so $('#testTime').text(data.testTime.slice(3)) is likely what you want. If it contained HTML tags, $('#testTime').html(data.testTime.slice(3)) is likely what you want. PS: Jason is a person's name. JSON is what you meant.
22nd Aug 2020, 2:18 PM
Josh Greig
Josh Greig - avatar