Hi

I am currently developing a mobile / tablet application and i've run into a stump.
I have a webview that loads a form from a website that i have no control over, this website utilises the django platform.

So the situation is this:

The form on the foreign website uses ajax to send through a JSON encode string and returns a JSON object. - simple

My issue is this, From a desktop browser or a mobile browser, this process works perfectly fine.
Enter credentials->returns json->redirects to logged in backend.

From a Android WebView i keep getting this in the information log:
4376-4376/<package name> I/chromium﹕ [INFO:CONSOLE(72)] "[object Object]", source: <foreign site url> (72)
It doesn't redirect me either, It just sits at the login form.

My Code is below for the WebView:

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_maps);

        gWebView = (WebView) findViewById(R.id.statisticsmap);

        // Enable Javascript
        WebSettings webSettings = gWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);


        gWebView.setWebViewClient(new MyAppWebViewClient());
        gWebView.loadUrl(<clients url>);
        CookieManager.getInstance().setAcceptCookie(true);
        }

Is there some sort of websetting or permission that i am missing?
It just seems like the weview isn't processing the json.

I did notice that the foreign website does use a csrf token...

//set our CSRF Token for our ajax requests
    $.ajaxSetup({
    beforeSend: function(xhr, settings) {
        xhr.setRequestHeader("X-CSRFToken", $('[name="csrfmiddlewaretoken"]').val());
    }});
    document.getElementById('greenbtn').onclick = function(e) {
        e.preventDefault()
        json_object = {"Username" : $("#inputEmail").val(), "Password" : $("#inputPassword").val()};
        console.log(json_object);
        $.ajax({
            url: '/login',
            type: 'POST',
            contentType: 'application/json; charset=utf-8',
            data: JSON.stringify(json_object),
            dataType: 'json',
            success: function(result) {
                if (result["status"]=="Success"){
                    $('.alert-success').show();
                    window.location.replace("/");
                }
                else {
                    $('.alert-warning').show();
                    $("#inputPassword").val("");
                }
            },
            fail: function(result){
                alert("somethings has gone wrong, Please try again later");
                $("#usernameInp").val("");
                $("#passwordInp").val("");
            }
        });
    };

I have read that the Android system doesnt respond well to : window.location.replace - but i think that might have been a very old article,

Any help would be greatly appreciated!

Thank you in advance.

My Apologies,
I have sorted it out....

I had the endsWith section in the MyAppWebViewClient returning true instead of false.... Simple error.

public class MyAppWebViewClient extends WebViewClient {

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {

        if(Uri.parse(url).getHost().endsWith("<client url>")) {
            return false;
        }


        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.