Can more than one AJAX call be made in the same form?


#1

I have a form that has two AJAX calls to our DB server. The first works fine - but after that, the second triggers the error:

“Uncaught ReferenceError: AJAX is not defined” (and gives the line number of the second AJAX call)

My test code is here :

var queryNetIDVotes = "SELECT audiencevoters.netID, voting.team_name, voting.rating FROM voting INNER JOIN audiencevoters ON voting.aud_id=audiencevoters.aud_id ORDER BY audiencevoters.netID";
  req2 = Ajax("http:/XXXXXXXX/XXXXX/ajax-connection.php", "POST", "host=XXXXXXX&user=XXXXXX&pass=" + pw + "&database=XXXXXXX&query=" + queryNetIDVotes);
 
  if (req2.status == 200) {    //everything worked. :P
    allNetIDTeamRatings = JSON.parse(req2.responseText);
    console.log("The all data parsed are: allNetIDTeamRatings");
  } else 
      console.log("Error Network first call Will Robinson");
// second DB call 
            addQuery = "INSERT INTO audiencevoters VALUES('`' + netID + '`,`' + firstname + '`,`' + lastname + '`')";   
            req3 = AJAX("XXXXXXXX/XXXX/ajax-connection.php", "POST", "host=XXXXXXXXX&user=clc90595&pass=" + pw + "&database=XXXXXXXX&query=" + addQuery);
            // return message to user
            if (req3.status == 200) {
                second = JSON.parse(req3.responseText);
                console.log(second);
            } else
                NSB.MsgBox("Error network second call");

This is run on response to a button click event.
My question: can you run more than one AJAX call in a form? Thanks -


#2

@cindycc, could you clean up the paragraphing of the code so it is easier to read? Is the second Ajax call in the else condition?

I inserted triple left tics around your code as a start.


#3

So sorry - the problem: I had AJAX capitalized in the second call. Duh.


#4

Great!

Can I call your attention to something else? Allowing database comments to be sent directly via Ajax is extremely dangerous in the outside world. Only do this if the client is completely trusted and not in the outside world.

Little Bobby Tables is coming to mind…


#5

Very true. We are in a closed system - it is a class on a secure, limited
access server.

Say - do you know how to access and use Google Places using the Google
control in appStudio? Is it possible? I put the link to the Places library
in the ExtraHeaders property - appears app not seeing it.

Thanks

Cindy


#6

I saw that question in another thread. Anything which can be done in JavaScript can be done in AppStudio. However, I haven’t done this particular thing, so do not have a specific answer on how to do this.