Reputation: 423
I'm trying to create a list links using jquery. I'm using this code to retreive the date
$.getJSON('/chapersRetrival.php', function(data)
{
$.each(data, function(index, array) {
$("<a/>").attr({href: 'http://www.mangamanga.com/chapNo='+array['chapterID']+'&#pageNo=1>', title:array['mangaName'] + array['chapterName']} + array['chapterNumber']).appendTo("#mangaChpaters");
});
});
just wondering if there is anything wrong with regards to who the code is written ?
Upvotes: 0
Views: 109
Reputation: 97601
Well for a start, you can make it much more readable by adding some line breaks. Also, the this
pointer can be used as a shorthand inside the function to point to the current piece of data:
$.getJSON('/chapersRetrival.php', function(data) {
$.each(data, function() {
$("<a/>").attr({
href: 'http://www.mangamanga.com/chapNo='+this['chapterID']+'&#pageNo=1>',
title: this['mangaName'] + this['chapterName'] + this['chapterNumber']
}).appendTo("#mangaChpaters");
});
});
Also, you seem to have made a couple of spelling mistakes/typos, which have been "fixed" here:
$.getJSON('/chaptersRetrieval.php', function(data) {
$.each(data, function() {
$("<a/>").attr({
href: 'http://www.mangamanga.com/chapNo='+this['chapterID']+'#pageNo=1',
title: this['mangaName'] + this['chapterName'] + this['chapterNumber']
}).appendTo("#mangaChapters");
});
});
Upvotes: 0
Reputation: 65952
You have a closing }
too soon. In needs to come after your concatenation of array['chapterNumber']
. Otherwise it looks fine to me.
The fix:
$.getJSON('/chapersRetrival.php', function(data)
{
$.each(data, function(index, array) {
$("<a/>").attr({href: 'http://www.mangamanga.com/chapNo='+array['chapterID']+'&#pageNo=1>', title:array['mangaName'] + array['chapterName'] + array['chapterNumber']}).appendTo("#mangaChpaters");
});
});
Upvotes: 1