Forum Discussion

AustinK's avatar
AustinK
Qrew Commander
5 years ago

Re: RESTful API Header

Are you getting any errors in console? I think there should be an error for line 78 saying 'ticket' is undefined. I'm really tired today so I may miss something obvious here.

I think I see now, those things still needed to be done though. I believe it is a scope issue for line 71. That variable is scoped to that function and is not a global variable. Once outside of that function the variable does not exist. 

You could go about this multiple ways. You could attach the variable to the window object, which turns it global but is kind of dirty. Or you could declare your variable outside of your function and then use it in the function at a local level in a certain way that will affect the global variable.

If you declare it in your code like this in the same code block but outside of the function:

var ticket = ''

Then in your function change line 71 to be this without the var at the beginning:

ticket = JSON.parse(xmlHttp.responseText);

That should cause ticket in the function to update the global variable. If it does not, we can try attaching ticket to the window object.

19 Replies

  • AdamKeever1's avatar
    AdamKeever1
    Qrew Commander
    There are no errors. I tried declaring 'ticket' as global as you noted above and still no result. The var ticket = '' uses two apostrophes and not a single quotation mark, correct?


    ------------------------------
    Adam Keever
    ------------------------------
    • AdamKeever1's avatar
      AdamKeever1
      Qrew Commander
      I checked the console log and found this syntax error:
      [MY TABLE]?a=dbpage&pageID=7&rid=1923:82 Uncaught SyntaxError: Identifier​

      This is the line that the <script> for the query begins.



      ------------------------------
      Adam Keever
      ------------------------------

      • AustinK's avatar
        AustinK
        Qrew Commander
        I do not have time to fully test this right now but I will later if this does not make it work for you. Those errors are because you try and initialize that variable multiple times. 

        You set it as a const on line 62 and then also set it as const on line 99. I believe if you remove the const on line 99 it should work.

        There is a second part to this though. When you set a variable as const you are saying it should not be allowed to be changed, kind of(it gets complicated.) So when you set it initially at line 62 that is fine. When you try and re-assign the variable later on it is blocked because it is a const.

        If you set the first variable to be var instead of const (and then remove the const from line 99 still) that may work. Like I said I will try and actually test this tomorrow or possibly later today when I get a chance.