嗨,我正在尝试获取我使用PHP获取的数据。
该页面名为twitter-fetch.php
现在我知道的是,该页面现在填充了转换为关联数组的json数据,因为我对数据执行了json_decode()操作。(如果我错了,请纠正我)。
现在我要做的是使用ajax调用该页面。
该项目的名称是phone。我的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!');
}
});
});这是我使用json_decode并将其存储在$string中的php代码行
$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);更新:- $.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);
});发布于 2014-06-30 22:55:13
现在,您正在向链接[website directory]/phone/php/twitter-fetch.php发送一个请求,该请求可能不是一个真正的文件。相反,您需要使用../返回phone/目录,然后将php/twitter-fetch.php
$(document).ready(function(){
$.ajax({
url: '../php/twitter-fetch.php',
type:'POST',
contentType: 'application/json',
dataType: 'json',
success: function(result){
console.log(result);
alert('success!');
}
});
});此外,请记住,当您将/放在相对链接的开头时,该相对链接将被附加到网站目录中。如果您希望将其附加到当前文件所在的最低目录,请不要将/放在开头。
https://stackoverflow.com/questions/24492555
复制相似问题