我是新的gwt和新的使用Firebug。我的gwt版本是2.0.0。使用eclipse和WAMP。我的IIS停止运行WAMP apache。我在Firefox
运行我的节目,我有有效的JSON结果从位于“http://localhost/phpmyadmin/tesdb3/datauser.php”json解析器空结果
{"item": [{"kode":"002","nama":"bambang gentolet"},
{"kode":"012","nama":"Algiz"}]}
我添加了XML与
<inherits name='com.google.gwt.json.JSON'/>
<inherits name="com.google.gwt.http.HTTP" />
tesdb3.php然后我试图说明它在GWT与此代码。
public class Tesdb3 implements EntryPoint {
String url= "http://localhost/phpmyadmin/tesdb3/datauser.php";
public void LoadData() throws RequestException{
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, URL.encode(url));
builder.sendRequest(null, new RequestCallback(){
@Override
public void onError(Request request, Throwable exception) {
Window.alert("error " + exception);
}
public void onResponseReceived(Request request,
Response response) {
if (200 == response.getStatusCode()) {
Window.alert("ok -" + response.getText() + "-" + response.getStatusCode());
} else {
Window.alert("error2 -" + response.getText()+ response.getStatusText() + "-" + response.getStatusCode());
}
}
});
}
public void onModuleLoad() {
try {
LoadData();
} catch (RequestException e) {
e.printStackTrace();
}
}
}
我在开发模式下运行它。不是托管模式。
我的代码没有显示任何错误。但窗口警报的结果是“error2 --OK-0”。
result Net from firebug is 7 request:
get Tesdb3.html?gwt.codeserv = 200ok
get Tesdb3.css = 200ok
get tesdb3.nocache.js = 200ok
get hosted.html?tesdb3 = aborted
get standard.css = 304 not modified
get hosted.html?tesdb3 = 403 not modified
get datauser.php = 200ok
我的问题是:
为什么响应状态代码为0,并且响应状态的文字是 'OK'?在json或Java代码中没有错误。
为什么response.getText
是空的?为什么我无法获得任何json结果甚至是单个字符?
请帮帮我。已经2个月了,我尝试用多种来源类型来解决这个问题,并且我无法获得单个结果。
这是我datauser.php
header('Content-type: application/json; charset=UTF-8');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
$link = mysql_connect("localhost", "root", "")
or die("Could not connect : " . mysql_error());
mysql_select_db("tesku1") or die("Could not select database" . mysql_error());
$query = "select * from tabel1";
$result = mysql_query($query);
$jumlah_data = mysql_num_rows($result);
echo '[';
for ($i=0; $i<=count($result); $i++){
$row = mysql_fetch_array($result);
echo '{';
echo "\"kode\":\"$row[kode]\",";
echo "\"nama\":\"$row[nama]\"";
if ($i==count($result)){
echo '}';
}else
echo '},';
}
echo ']';
mysql_free_result($result);
你可以通过代理运行请求,或使用萤火虫,告诉我们确切的反应是什么? – tgdavies 2010-06-07 13:04:40
您是否为您的JSON输出设置了正确的标题? 'header('Content-type:application/json; charset = UTF-8');'那么其他状态类型呢?就像404s或500s“通过”还是导致状态码0? – 2010-06-07 13:18:07
@tdavies:他已经发布了来自Firebug的Net标签的结果。 – 2010-06-07 13:19:02