如何通过.apk中的javascript调用php

时间:2013-02-04 07:14:42

标签: php javascript android webview

如何通过javascript在apk中调用php,我正在使用webview和html5 javascript和jquery

我想从php

中检索json数据
function ajaxFunction() {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.addRequestInterceptor(new RequestAcceptEncoding());
    httpclient.addResponseInterceptor(new ResponseContentEncoding());
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://www.smartcloudinfo.com/game/RainbowTreasure(IPAD)/RT_IPADV1.0.40/json.php");
        try {
            // Add your data
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
            nameValuePairs.add(new BasicNameValuePair("line_value",20));
            nameValuePairs.add(new BasicNameValuePair("stake_value",0.2));
            nameValuePairs.add(new BasicNameValuePair("balance_value",updated_Balance));  
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            // Execute HTTP Post Request
            HttpResponse response = httpclient.execute(httppost);
             alert("found"+HttpResponse response);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }
     }

1 个答案:

答案 0 :(得分:0)

您需要使用ajax。 Jquery具有内置功能来进行ajax调用。特别是如果你想在json中发布你的答案,那么在jquery中也会调用这些东西。

以下是jquery页面中的一个简单示例:

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() {
  $(this).addClass("done");
});

或者对于JSON:

$.getJSON("test.js", { name: "John", time: "2pm" }, function(json) {
    alert("JSON Data: " + json.users[3].name);
    });