Javascript .getJSON.done()函数不使用';t调用else.fail()始终被调用
我已经编写了一个html页面,它接受用户的输入,点击submit调用javascript函数。html页面如下所示:Javascript .getJSON.done()函数不使用';t调用else.fail()始终被调用,javascript,php,jquery,Javascript,Php,Jquery,我已经编写了一个html页面,它接受用户的输入,点击submit调用javascript函数。html页面如下所示: <body> <input type="text" id="input_"/> <input type="button" id="submit" value="Get tweets"/> <div id="results"></div> </body> .g
<body>
<input type="text" id="input_"/>
<input type="button" id="submit" value="Get tweets"/>
<div id="results"></div>
</body>
.getJSON中的url实际上是localhost/tweets.php?q=(userInput),但该url在getJSON.done函数中不返回任何内容,但是如果我在控制台上使用.fail(err)和display err,它会在控制台上打印返回的数据。另外,如果我在浏览时手动打开例如:localhost/tweets.php?q=mkx,则数据将显示在浏览器上。我似乎在代码中找不到任何问题。tweets.php文件如下:
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23'.$_GET["q"];
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(true);
欢迎提供任何帮助。在浏览器中打开时,输出是什么样子的?它是有效的json吗?是的,它是有效的json,如下:{“statuses”:[{“metadata”:{“iso_language_code”:“en”,“result_type”:“recent”},“created_at:“Fri Jul 24 17:36:47+0000 2015”,“id”:624634345051979776,“id_str”:“624634345051979776”,…请检查服务器或您的php应用程序是否返回有效的json格式响应。需要在浏览器开发工具网络中检查实际请求以获取更多线索…状态、url、响应正文等响应类型
应用程序/json
?在浏览器中打开时,输出是什么样子的?它是有效的json吗?是有效的json例如:{“statuses”:[{“metadata”:{“iso_语言代码”:“en”,“结果类型”:“recent”},“created_at:“Fri Jul 24 17:36:47+0000 2015”,“id”:624634345051979776,“id_str”:“624634345051979776”,…请检查服务器或php应用程序是否返回有效的json格式响应。需要在浏览器开发工具网络中检查实际请求以获取更多线索…状态、url、响应正文等响应类型应用程序/json
??
$url = 'https://api.twitter.com/1.1/search/tweets.json';
$getfield = '?q=%23'.$_GET["q"];
$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(true);