jan321
jan321

Reputation: 3

GET and POST ajax Android Web view

In my Android App a Webview is showing a website with 2 buttons. One of those sends data via POST and the other one via GET, like this:

$("#post").click(function() {
            $.ajax({
                type: "POST",
                url: "test.php",
                dataType: "text",
                data: { name: "Max", time: "7pm" },
                success: function(data) {
                    $("body").append("<p>"+data+"</p>");
                }
             });

My question is: is it possible to get the sent data into the android application ?

Upvotes: 0

Views: 2654

Answers (2)

s1m3n
s1m3n

Reputation: 623

I think you are mixing concepts here.

The WebView is separate from your Android app, so the POST data is not really visible from your app. Imagine you open a WebView for your bank's website and from the app you could get the POST data: you would be able to get the username, password... a security hole would be a very mild name for it.

If the web page you are showing with the WebView is yours (you control it) you can do many things to obtain the data, but basically you would have your app "query" the web server for the data or maybe have the web server "push" the data to the app. You could even append the info to a URL and do a redirect, which could be intercepted with a WebView and parsed.

The other option is to use WebAppInterface (see: http://developer.android.com/guide/webapps/webview.html) which basically adds a JS object that allows to interact with your Android app.

Upvotes: 0

Define JSInterface and pass a reference to webview.addJavascriptInterface() to send data from javascript to android and webView.loadUrl("javascript: /*some javascript*/ "); to send data from android to javascript.

Upvotes: 1

Related Questions