I have a Webpage with a MYSQL Database. I can easily Insert data in it but when it comes to "Select" it throws "("Couldn't retrieve JSON")" is it even possbile to get this data from a Webserver with the jetty Server. I acually plan to use Phonegap which supports PHP http://phonegap.com/2012/05/02/phonegap-explained-visually/
RequestBuilder request = new RequestBuilder(RequestBuilder.POST,URL.encode("http://testeddd.com/test.php"));
String name = mioUsername.getText();
String pssw = miaPassword.getText();
JSONObject jsonValue = new JSONObject();
jsonValue.put("myusername", new JSONString(name));
jsonValue.put("mypassword", new JSONString(pssw));
request.setHeader("Content-Type", "application/json");
try {
request.sendRequest(jsonValue.toString(),new RequestCallback() {
@Override
public void onResponseReceived(Request request, Response response) {
if (200 == response.getStatusCode()) {
try {
JSONValue jsonValue = JSONParser.parse(response.getText());
JSONArray jsonArray = jsonValue.isArray();
if (jsonArray != null) {
RootPanel.get().clear();
RootPanel.get().add(new MapComp());
} else {
Dialogs.alert("1", "fault", null);
} } catch (JSONException e) {
Dialogs.alert("2", e.toString(), null);
}
} else {
Dialogs.alert("request none", "Couldn't retrieve JSON (" + response.getStatusText() + ")", null);
}
}
@Override
public void onError(Request request, Throwable exception) {
//displayError("Couldn't retrieve JSON");
}
});
} catch (com.google.gwt.http.client.RequestException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
my php file:
<?php
header('Content-Type: text/javascript');
header('Cache-Control: no-cache');
header('Pragma: no-cache');
$str = $_POST['param'];
$con=mysqli_connect("llxxllxxx","lll","lll","lll");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM xxx".$str);
$i = 0;
while( $row = mysqli_fetch_array($result, MYSQLI_ASSOC) )
{
$array[$i] = $row;
$i++;
}
$result->close();
$con->close();
print json_encode($array);
?>