0

I have a question on basic browser-server functionality. I am trying to get my JS to see my apex variable resStatusCode which is set to the webservice's res code.

public static Integer resStatusCode {get;set;}
...
resStatusCode = res.getStatusCode();

I have an actionFunction:

<apex:actionFunction name="refreshBankData" action="{!bankDataButton}" reRender="form" status="spinnerStatus1" oncomplete="closeWindow();"/>

and a JS function:

function closeWindow() {
    console.log('res: ' + '{!resStatusCode}');
    if({!resStatusCode} == 200){
        alert('Success - Your Bank Data Has Been Refreshed');
        setTimeout(function(){
            self.close();
        },1000);
    }
}

My JS is unable to view the resStatusCode because (I assume) that the apex code has not yet come to the browser side. The value is still stuck on the back end. How would I be able to pull the value to the browser without having to do a refresh? Could anyone explain what is going on here with data storage?

My variable has to be static because I am using @RemoteAction with my webcallout

2

A key point from the apex:actionFunction documentation is:

apex:actionFunction defines a new JavaScript function which can then be called from within a block of JavaScript code

so you need to call the automatically generated JavaScript function refreshBankData somewhere. (Presumably you are.)

To pick up new values from the controller using Visualforce's {! ... } expression, the controller property cannot be static, and the part of the page that has the {! ... } expression needs to be within the part of the page that is re-rendered (as the new value is returned in the replacement HTML returned by the Ajax call).

  • you are right, I needed to have the JS in the section that I was reRendering so it would pick up the new value. The only thing is that the static variable is working as is so I don't need to change that. All is working now. Thank you! – Olivia May 18 '17 at 22:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.