B4J Question [BANano] TypeError: Failed to fetch

tango

Active Member
Licensed User
Longtime User
i can never pass this error:TypeError: Failed to fetch
is there any help?

PHP:
$data = $_GET['data'];
header('content-type: application/json; charset=utf-8');
$conn = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
    If ($conn->connect_error) {
        $response = $conn->connect_error;
        $output = json_encode(Array("response" => $response));
        die($output);
    }
 
    mysqli_set_charset($conn, 'utf8');
   
   
    $sql = mysqli_real_escape_string($conn, $data);
    $conn->autocommit(False);
    $result = $conn->query($sql);
    If (!$result){
        $response = $conn->error;
        $output = json_encode(Array("response" => $response));
       
    }  else {
       
        // Fetch all
        $rows = Array();
        While ($row = $result->fetch_assoc()) {
            $rows[] = $row;
        }
        $output = json_encode(array("response" => "OK", "data" => $rows));
    }  
      echo($output);
    $conn->close();

B4X:
Public Sub PostString(url As String,data As String)

    Dim fetch As BANanoFetch
    Dim fetchOptions As BANanoFetchOptions
    Dim fetchResponse As BANanoFetchResponse
   
    Dim jsonObj As Object ' <-----------------------
    Dim Error As String
   
    fetchOptions.Initialize
    fetchOptions.Method = "POST"
    fetchOptions.Body = data
    fetchOptions.Headers = CreateMap("Content-type": "application/json; charset=UTF-8")
   
    fetch.Initialize(url, fetchOptions)
    Try
        SKTools.ShowToast("try","default", 13000, True)

        ' wait for the response
        fetchResponse = BANano.Await(fetch)
        ' wait for the json part of the response
        jsonObj = BANano.Await(fetchResponse.Json) ' <----------------------- this will still crash if you use e.g. var_dumpor anything that returns invalid json
       
        ' overkill as we already have the json parsed here, but for demo's sake so we can do a GetString later
        Dim json As JSONGenerator
        If BANano.IsArray(jsonObj) Then ' <-----------------------
            json.Initialize2(jsonObj)
        Else
            If BANano.IsMap(jsonObj) Then
                json.Initialize(jsonObj)
            End If
        End If
    Catch(Error)
       
        SKTools.ShowToast("hata:"&Error,"default", 13000, True)
    End Try
End Sub
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…