Я пытаюсь использовать JQuery для загрузки результатов из базы данных mysql, генерируя вывод json-p.
Это пример вывода, сгенерированного скриптом 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');
Любая помощь приветствуется,
Спасибо
Рози
Вот код (взято из примера, предоставленного Джо Челлманом
<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>
Задача ещё не решена.
Других решений пока нет …