嗨我试图获取我使用PHP获取的数据。试图从php页面获取数据使用jQuery获取json数据
页名为Twitter的fetch.php
现在我所知道的是,该页面现在充满了()的数据转换为关联数组,因为我json_decode JSON数据。 (如果我错了,请纠正我)。
现在我想要做的就是使用ajax调用该页面。
该项目的名称是手机。我的js文件位于js文件夹中。和twitter-fetch.php在php文件夹中。我只是想看到的结果在控制台现在,帮...皱眉
我还是新来的AJAX和JSON,所以我真的不知道在我在这里做什么
$(document).ready(function(){
$.ajax({
url: '/phone/php/twitter-fetch.php',
type:'POST',
contentType: 'application/json',
dataType: 'json',
success: function(result){
console.log(result);
alert('success!');
}
});
});
这个php的线,我用json_decode并将其存储在$字符串
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$getfield = '?q=%23forsale&result_type=recent&count=100';
//the TwitterAPIExchange is a PHP Wrapper that I used
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
UPDATE:----- $ .getJson
$.getJSON('./php/twitter-fetch.php',function(result){
var output = $.map(result, function(item, index){
var listitem = $('<li></li>');
$('<h2>'+item.user.name+'</h2>').appendTo(listitem);
return listitem;
console.log(listitem);
});
$('#js-result-list').html(output);
});
然后是什么问题? –
您是否收到成功消息? – Ninad
我没有得到任何东西... – Don