Android Question Post/Get not working

monic

Active Member
Licensed User
Longtime User
Hi first week using basic/B4A and I'm stuck searched around the forum and stackoverflow and can't get to the bottom of why this won't work.

I have a simple textbox and button and want to send to a php script for processing. The variable q is required for debugging purpose I've echoed the q.Text.

Can anyone point me to a fix?

B4X:
#Region  Project Attributes
    #ApplicationLabel: Search
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: True
#End Region

'Activity module
Sub Process_Globals
  'These global variables will be declared once when the application starts.
  'These variables can be accessed from all modules.

End Sub

Sub Globals
  'These global variables will be redeclared each time the activity is created.
  'These variables can only be accessed from this module.
  Dim q As EditText
  q.Initialize("q")
  Dim cmdSubmit As Button
  cmdSubmit.Initialize("cmdSubmit")
  cmdSubmit.Text = "Search"
    Private WebView1 As WebView
End Sub

Sub Activity_Create(FirstTime As Boolean)
  Activity.AddView(q, 10, 10, 100%x-20,100)
  Activity.AddView(cmdSubmit, 10, 110, 100%x-20,100)
End Sub

Sub cmdSubmit_Click
  Dim jobPost As HttpJob
  jobPost.Initialize("JobPostName",Me)
    jobPost.PostString("http://server.com/i.php?var=1","&q="&q.Text)
End Sub

Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "JobPostName"
                ToastMessageShow(q.Text, True)
                        WebView1.Initialize("WebView1_Click")
    Activity.LoadLayout("WebView")
    WebView1.loadhtml(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
 

thedesolatesoul

Expert
Licensed User
Longtime User
Firstly, in Globals, you shouldnt write any code, only declare the variables.
Move all the initialize etc to Activity_Create.

Secondly, what result do you see? Do you anything in the Logs or the ToastMessages?
Put a Log in cmdSubmit too to make sure it is being executed.
 
Upvote 0

monic

Active Member
Licensed User
Longtime User
I moved the intialize parts and the app crashes move them back and now ok, I can see the page requested loads but no variables are being sent to the php script as have written a small php script to show any variable and none are being executed. In toast the variable q is being displayed just not being sent.
 
Upvote 0
Top