通过JavaScript从另一个页面获取JSON数据 [英] Get JSON data from another page via JavaScript

查看:152
本文介绍了通过JavaScript从另一个页面获取JSON数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,我想在其中添加几个控件 当我单击第一个控件时,我希望我的JavaScript打开特定的JSONpage,对内容进行语法分析,然后在特定的<DIV id="one">中输出内容.然后,当我在div id ="one"中选择某些元素时,我希望JavaScript连接到另一个JSON页面并从那里获取另一个数据数组.

I have a page where I want to add couple of controls when I click on 1st control, I want my javascript to open particular JSONpage, gram the content and then output the content in specific <DIV id="one">. Then, when I select some of the elements in div id="one", I want The JavaScript to connect to another JSON page and get another array of data from there.

我的问题-如何处理JSON部分? 换句话说,我如何获得以下版本的JavaScript版本:

My question - how do I do the JSON part? In other words, how do I get JavaScript version of:

$dataSet = json_decode(file_get_contents($url), true);

我是JavaScript的新手,这东西要花很多时间!

I am new to JavaScript and this thing takes so much time!!

推荐答案

可以正常工作

function getDates() {
    jQuery(function($) {                   
        $.ajax( {   
            url : "jsonPage.php",
            type : "GET",
            success : function(data) {
                // get the data string and convert it to a JSON object.
                var jsonData = JSON.parse(data);
                var date = new Array();                                
                var i = -1;                               
                $.each(jsonData, function(Idx, Value) {
                    $.each(Value, function(x, y) {
                        if(x == 'date')
                        {
                            i = i + 1;
                            date[i] = y;
                        }                                                
                    });
                });
                //output my dates; [0] in this case         
                $("#testArea").html(date[0]);
            }
        });
    });
}

这篇关于通过JavaScript从另一个页面获取JSON数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆