使用ajax从数据库加载结果

时间:2014-11-04 00:22:54

标签: php jquery mysql ajax jsonp

我试图通过生成json-p输出来使用JQuery从mysql数据库加载结果。

这是php脚本生成的示例输出:

([{"portfolio":"Foreign Affairs and Trade Portfolio","agency":"Department of Foreign Affairs and Trade ","program":"Programme 1.10: Official Development Assistance - Emergency, Humanitarian and Refugee Programme","funding":{"last":"182606","current":"338636","plus1":"349680","plus2":"361875","plus3":"373843"}},{"portfolio":"Immigration and Border Protection Portfolio","agency":"Migration Review Tribunal and Refugee Review Tribunal ","program":"Programme 1.1: Final independent merits review of decisions concerning refugee status and the refusal or cancellation of migration and refugee visas.","funding":{"last":"82985","current":"60667","plus1":"60656","plus2":"61237","plus3":"60897"}},{"portfolio":"Immigration and Border Protection Portfolio","agency":"Department of Immigration and Border Protection","program":"Programme 2.1: Refugee and Humanitarian Assistance","funding":{"last":"61086","current":"69320","plus1":"42720","plus2":"30774","plus3":"30158"}},{"portfolio":"Immigration and Border Protection Portfolio","agency":"Department of Immigration and Border Protection","program":"Programme 2.2: Refugee and Humanitarian Assistance ","funding":{"last":"66243","current":"66563","plus1":"73841","plus2":"91595","plus3":"92895"}}]);

我在控制台或网页上没有得到任何结果,我想知道这看起来是否合适?我以前从未使用过Ajax。

输出看起来是否正确?它有这个标签    header('Content-type: application/json');

任何帮助表示赞赏,

感谢 罗西 这是代码(改编自Joe Chellman提供的示例

<form action="" id="rep-lookup">
        <div>
        <label for="txt-program">search:</label>
        <input type="text" id="txt-program" name="program" required />
        </div>

        <div>
        <input type="submit" id="btn-lookup" value="Look up my reps" />
        </div>
    </form>

    <div id="rep-lookup-results">
        <em>When senators are found, they will be displayed here.</em>
    </div>




        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
        <script>window.jQuery || document.write('<script src="_scripts/jquery.min.js"><\/script>')</script>
        <script>
        'use strict';

        $(document).ready(function () {
            $('#rep-lookup').submit(function(e){
                e.preventDefault();

                var 
                    program = $('#txt-program').val(),
                    $resultsArea = $('#rep-lookup-results');

                var requestURL = 'http://infoaus.net/budget/program_results_json.php?callback=?';

                $.getJSON(requestURL, {

                    'program' : program,
                }, function(data){
                    console.log(data);


                });
            });
        });


        </script>

0 个答案:

没有答案