doushui3061 2013-03-04 19:55
浏览 54
已采纳

javascript或php中的“状态”?

I've been working with FLEX for while and I had there some "states" declaration. For those who are not sure what I mean, it's like a couple of different pages between you can translate, setting a current state.
Now I want to get started with Facebook development, and I don't know how to pass between pages I created with html. I guess that would be possible using javascript rather than php, but I am not sure how. Can someone please help me?

A scheme of what I would like to do is:

              tigger1  
State A-------------------->State B

              trigger2      
State B-------------------->State C

The following example shows a login panel with 2 states: default, for showing the login form, and Register for showing the form for registration. The current state change is triggered by an action (in this case, pressing the Linkbutton). Mainly, what states do, is displaying proper content based on what the user should be able to do under each state. So, if for example I want to do a payment form, after the user attempts to make the payment, if the payment was successfully done, I would have a "Thank_you" state, while if the payment failed, I would have a "Try_again" state. How can this be done using php/js?

Code sample of login/register panel (from adobe flex website, also running example and full code can be found in the link):

<!-- The Application class states property defines the view states.-->
<s:states>
    <s:State name="default"/>    
    <s:State name="Register"/>
</s:states>

<!-- Set title of the Panel container based on the view state.-->
<s:Panel id="loginPanel" 
    title="Login" title.Register="Register">     

    <s:Form id="loginForm">
        <s:FormItem label="Username:">
            <s:TextInput/>
        </s:FormItem>
        <s:FormItem label="Password:">
            <s:TextInput/>
        </s:FormItem>


        <s:FormItem id="confirm" label="Confirm:" includeIn="Register">
            <!-- Add a TextInput control to the form ONLY for the Register view state. -->           
            <s:TextInput/>
        </s:FormItem>            

        <s:FormItem>            
            <!-- Use the LinkButton to change view state.-->
                <!-- Set label of the control based on the view state.-->
                <mx:LinkButton id="registerLink"
                    label="Need to Register?" 
                    label.Register="Return to Login"
                    click="currentState="Register"
                    click.Register="currentState="default"/>
                <s:Button id="loginButton" 
                    label="Login" label.Register="Register"/>
        </s:FormItem>            
    </s:Form>
</s:Panel>

Thanks in advance

  • 写回答

1条回答 默认 最新

  • drux41001 2013-03-04 20:33
    关注

    Right, I think I understand your question. Flex (or Flash) works with ongoing variables (or states) because it is a long-running program, controlled by events from a user interface.

    Web programming isn't like that. Each page is served separately, from a program that lives only for the duration of that request, and so state has to be maintained on the client side by the use of cookies. Since the server often needs to be aware of user state, the cookie (if one is set) is supplied by the browser to the server automatically, who can cross-reference the cookie's value with things that this user has done before.

    If the cookie value is unique, it can be used to cross-reference a session store, which is a set of values just for one user. PHP offers this inside its $_SESSION feature. This is quite a big topic in itself, so I would recommend web-searching for "PHP session examples" - here and on the web - and playing with some code. Real examples will show you how it all works.

    Edit: turns out states (variables) and states (UI variants) are different things! See the comments for more details.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口