getJSON数组错误

时间:2016-11-11 15:56:13

标签: jquery getjson

我有一个包含如下数组的文件:

<script>
var articles = [
[
"Vanilla JS Browser Default Java Script.",
"http://www.9lessons.info/2015/09/vanilla-js-browser-default-java-script.html"
],
[
"Facebook Style Background Image Upload and Position Adjustment.",
"http://www.9lessons.info/2015/02/facebook-style-background-image-upload.html"
],
[
"Create a RESTful services using Slim PHP Framework",
"http://www.9lessons.info/2014/12/create-restful-services-using-slim-php.html"
],

[
"Pagination with Jquery, PHP, Ajax and MySQL.",
"http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and.html"
],
[
"Ajax Select and Upload Multiple Images with Jquery",
"http://www.9lessons.info/2013/09/multiple-ajax-image-upload-jquery.html"
]
];
</script>

在其他文件中我有一个getJSON函数,它将获取数组:

$(document).ready(function () {
                /*
                 $("#notificationButton").click(function(){
                 var x = Math.floor((Math.random() * 5) + 1); // Random number between 1 to 10 
                 var title =articles[x][0];
                 var desc ='Most popular article.';
                 var url =articles[x][1];
                 notifyBrowser(title,desc,url);
                 return false;
                 });
                 */ var title;
                    var desc;
                    var url;
                    $.getJSON("data.php", function (data) {
                    var articles = [];
                    articles = data;
                    var x = Math.floor((Math.random() * 5) + 1); /* Random number between 1 to 10*/
                    title = articles[x][0];
                    desc = 'Most popular article.';
                    url = articles[x][1];   
                    });   
                    notifyBrowser(title, desc, url);

            });

我的问题是我没有在notifyBrowser(title,desc,url)中获取var title,desc和url;因为notifyBrowser(title,desc,url);在getJSON中工作。我该怎么办?

0 个答案:

没有答案