0

如何在apk中通过javascript调用php,我使用的是webwiew和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
        }
     }
4

1 回答 1

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);
    });
于 2013-02-04T07:16:29.823 回答