Android Question Enable javascript

SamSami

New Member
Hello . I am trying to retrieve information from the mysql database via the php file I uploaded to the host. But instead of information, I get a string that contains this text: "this site use javascript. please enable java script on your browser" .
I am new in b4a and thank you for your help.
When i test it on xampp it work excellent but don't work on real server .
The host I use is a free host. Do you think the problem is that the hosts are free? And have you any solution for that ?
 

JohnC

Expert
Licensed User
Longtime User
I'm assuming you are using HTTP Job to download the info from the PHP file. It appears that the PHP file uses javascript to build the page on the fly.

In these cases, the only solution is to:
1) Add a webview to your project and add the chrome client to it and enable javascript in it
2) Load the PHP page into the webview, which will run the javascript and hopefully produce the page correctly inside itself
3) Extract the resulting html code from the webview to obtain the info you need.

You will have to do some forum searching to find out how to do the above steps.
 
Upvote 0

SamSami

New Member
I'm assuming you are using HTTP Job to download the info from the PHP file. It appears that the PHP file uses javascript to build the page on the fly.

In these cases, the only solution is to:
1) Add a webview to your project and add the chrome client to it and enable javascript in it
2) Load the PHP page into the webview, which will run the javascript and hopefully produce the page correctly inside itself
3) Extract the resulting html code from the webview to obtain the info you need.

You will have to do some forum searching to find out how to do the above steps.
Thank you very much . I will try your solution . ?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
the way you are retrieving the information is not in a form that the server is expecting. the server also does not know you are not using a browser. it assumes you are and issues its standard reply to something it doesn't understand.

since you show no code, there is no way to know what you are doing. there is also no way to know what the server is supposed to do.

in general, a free host behaves like a paid host. both types of hosts permit some things and do not permit other things. there is no way to know what your server allows or does not allow. there is very little information to work with.
 
Upvote 0

SamSami

New Member
Thank you .
this is a sample of my codes in b4a and php . Instead of sending values separately, I send the whole SQL command to php. The same code and commands work properly in xampp. Do you think sending the whole sql command is a problem in terms of security?


b4a side:
    Dim ht10 As HttpJob
    ht10.Initialize("job10",Me)
    Dim my_query10 As String
    Dim host_user_pass_db As String = "&hostname=" & "my_host_name" & "&username=" & "my_user_name" & "&password=" & "my_pass" & "&databasename=" & "my_database"
    my_query10 = host_user_pass_db & "&action=" & "get_one_value"
    my_query10 = my_query10 & "&query=" & "SELECT col1 FROM table1 limit 1"
    ht10.PostString("http://example.com/my_php.php",my_query10)
    Wait For (ht10) jobdone(ht10 As HttpJob)
    If ht10.Success Then
        Log(ht10.GetString)
            label1.text = ht10.GetString
    Else
        ToastMessageShow(ht10.ErrorMessage,False)
    End If
    ht10.Release


php side:
    <?php

    $hostname=$_POST['hostname'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $databasename=$_POST['databasename'];

    $conn = new mysqli($hostname,$username,$password,$databasename);
    mysqli_query($conn,"SET NAMES utf8");
    If ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    } else{
    //echo "connect success";
    }

//-------------------------------

    switch ($action)
{

    Case "get_one_value":
        $query = $_POST['query'];
        $result = mysqli_query($conn,$query);
        If ($result !== False) {
        $row = mysqli_fetch_array($result);
        $value = $row[0];
        echo $value ;
        }   
        break;
}
        ?>



I get this string instead of the column value :

<html><body><script type="text/.
...
...
...
;</script><noscript>This site requires Javascript to work, please enable Javascript in your browser or use a browser with Javascript support</noscript></body></html>




thank you again for your help .
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
does the server only return html?

do you know for a fact that the server has received and parsed your query? you should echo everything the server has received. eg, does the server know what
$action is? you don't indicate this.

you only test for $result !== false. what happens if $result is false? you never bother to check.

some servers default to an html response unless you indicate otherwise as part of your request (eg: "&response=json"). does your server have any documentation?

i have no way to run your code on your server. debugging can be a little difficult, but you need to find out what the server sees and what kind of reply it is expecting to give. you host has configured the server, so his rules apply. your code needs to conform to them.
 
Upvote 0
Top