Okay - an easy answer for 99% of you. I have a custom class 'Users()'. In PHP I have all the values being populated correctly. When I go to Flash Builder - and do the test function - All the data comes back properly. However, when I click a button and refer to the lastResult property of the CallResponder - it comes up NULL the first time, and then if the button is clicked a second time it will return the correct result. What step am I missing? I had the same problem with something simliar last night and am getting BEYOND frustrated - especially since I know it is some SMALL detail I'm overlooking.
So just for clarification - lets say there is a button named button1
So button1's click handler:
1) Validates the text input properties
2) Asks the server if that user and password match
3) If they do - then I want it to grab all of that specific users info and put it into a User class. Again - when I test this function/method from within Flash Builder all the values come back as they should. It's just on the first button click they come back NULL...he second click they populate fine - I.E.-
Alert.show(currentUser.userFirstName); (First Click - NULL)
Alert.show(currentUser.userFirstName); (Second click - "Jack")
Any help is much appreciated!!! I am beating myself up over this and I know it is some simple, simple step I'm missing.
Thank you to all who take the time to help in advance!
-CS
To answer this simply, Flex is asynchronous... meaning the code you've executed in the next line may happen before your PHP code is done. The last result isn't populated yet when you've clicked the button the first time. The button clicking happens INSTANTLY, but the data needs a few seconds to come back. Likewise, the second time you click the button, you're going to get the last users info, not the current ones!!!
What you need to do is wait for the data to come back before you do anything. To do this, add an event listener to your service. It's called a "result" handler. There's a lot of good examples of this.
In the handler, go ahead and alert your popup with lastResult... or just, event.result. Should have what you're looking for.
Related
I'm working on a site (reworking is probably a better word as I did not build it originally) and am encountering the following weird scenario:
Users go to a page which shows a list of current events. This is called "whats-on".
I have added a link to this page which takes users to a full event calendar for the month in a typical calendar format. This page is called "event-calendar". Once on the page they can also select which month they want to see and what type of events they are interested in.
Users can click on an event listed in any date to navigate to a page with the event details. (page is event-details with a query that pulls the relevant event.) I have added a back button to the page under the event listing which will return them to the calendar showing the month and search results they just looked at. No issues there - I am using PHP $_SERVER['HTTP_REFERER'] and that works perfectly.
Here is the issue - if I just did a back() or history.go(-1) link on that button, it takes the user all the way back to "whats-on". The same thing happens when you click the browser back button. It just skips over "event-calendar" entirely.
This apparently happens on the site under other scenarios such as business listings and searches.
Obviously I do not want that behavior - I want the back button to go to the previously viewed page like it should!!
I cannot think of anything in the code that would cause this, but the original site developers included a whole bunch of JQuery packages such as jQuery UI, and I'm wondering if something could be interfering with the default back button behavior. Is that even possible??
I guess what I want to know is there is any JQuery code that would change the behavior of the back button so I could hunt it down and kill it!!
Just looking for ideas as to where to start looking.
Apparently the only way I can get it to work is to manipulate the browser history using
history.pushState({}, '', 'event-calendar?<plus whatever query was used to pull the data>');
on the calendar page itself.
This seems to work but what a stupid workaround. Wish I could find the original problem.
I made a BlackJack game using only php, and html of course for the layout. But what im trying to say is I need to only use PHP. So no javascript or something else.
My game is near completion, all that's left is the buttons.
I have 3 buttons, Start, Hit and the Stand button. These buttons work with forms, If you click Start it will submit a form where the player draws 2 cards and the dealer 1. Then if you click hit it submits a form where the page will give you 1 card. And by clicking Stand it lets the dealer play, drawing cards untill he hits => 17.
I hope you understand how my system works. (If not please tell me!)
Now when i start the program all buttons except Start needs to be disabled, when i submit the start form (Click the start button) it needs to disable the start button and enable all the others. I find this complicated to achieve since I've never done anything like this before without javascript.
I tried the following:
if (!isset($_SESSION["buttons"])){$_SESSION["buttons"]='disabled';}
This runs at the very start of the form, and in the buttons i echo the session out, so when i start it for the first time it disables all buttons, this works fine.
But when i click start, and run this:
if(FORM_start("Start")){
buttons();
}
And buttons(); being the following:
function buttons() {
$_SESSION["buttons"] = '';
}
It doesn't work the first time i click on Start, however if i click start again the other buttons get enabled suddenly.
So this way seems to work, only i need to press start twice, meaning i got 4 cards and the dealer 2.
Is there any way i can let it happen immediately or maybe there is some other way to disable/enable buttons using only PHP.
Thanks in advance!
Well, the easiest way to to do is setting up a numeric variable.
Lets say, it is $hands_played;
thus, the starting hand will be 0;
so, set your session to check is $hands_played = 0, if so, then add attribute disabled="disabled" to the button, if more than 0, don't.
but, to be honest, please use Javascript.
I was wondering if it was possible to trigger an event based on if a link WASN'T clicked?
I can't give you the specific code (it's for a game I work for), but here's what I need to happen (everything is set up perfectly except this little thing)
So you have item X that cannot be added to a players inventory if they don't use it right away.
You click open item X, and you either have the right key or you don't. If you don't, it's deleted. That's easy, the code is in place for that.
However, if for some reason they don't click the link, the item needs to be deleted immediately so it doesn't sit in the inventory. (I tagged JS because I think jquery is needed if it's something as dynamic as this)
Thanks in advance!
There is some point in your program that triggers it to delete the item. Closing of the inventory menu perhaps? That is an event you can capture, then figure out a way to call the appropriate code.
Put a image inside your link, put an onload event on your image, when the load event runs use setTimeout to run your "event", you'll also need a flag to tell if the link has been clicked (assuming that the link doesn't take you somewhere else, but if it does that then you just need the timer).
I have a form which sends data to a proccess page. Is it possible when the code in the process page is executed for the browser to jump back to the previous page?
EDIT
The reason i want this, is because i have a set of parameters which contains checkboxes. These parameters are echoed out via a while loop. I have a table where it shows which of those parameters are active. I would like to check the checkboxes by defualt where the corresponding parameter is in the table.
|||||||||||||||||||||||||||||||| Example ||||||||||||||||||||||||||||||
PARAMETERS:
T-Shirt: checked
Distance: checked
Race: unchecked
TABLE (parameters)
• T-Shirt
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||the example above checks the box if it already exists in the parameters table. When the user clicks back after the process page, the boxes he selected is checked.
Hope i am clear enough
Regards
I think a nice solution might be to implement a front controller for your webbage, a central script to include the appropirate page. Using a system like that, the user stays on the same page all the time even when other pages are loaded.
I haven't used a front controller in quite some time, so I won't write examples due to potential errors and poor coding. You can probably find some examples using google though, I wouldn't be surprised if the subject has been brought up here on Stackoverflow before either.
Even though I'll have to point out Griffin's solution is the best, if you're dead set on a redirect, simply have your PHP script execute the following lines:
echo '<script>document.history.go(-1);</script>';
die();
Or even
die('<script>document.history.go(-1);</script>');
It's a dirty solution, so I must advise against it.
Hey guys I am really messing up with this.
This is I'm doing: If there are 100 users to fetch from Database, I'm using pagination and showing 10 users at a time. when user will click on next page, he will get next 10 users through ajax(called ajax on click) and so on. I'm showing 10 page-links right now with first, next last and previous links.
This is how flow will go: On a.php created links and called ajax function with every link, passing url(b.php) & target(where I will get result), with url also passing clicked pageno., this pageno. will go to b.php and next 10 users will be shown with the help of ajax.
This is the problem: Currently I'm showing 1-10 links with first and last links, unable to show next and previous links because to redirect to next or previous, I am not getting the current page number on a.php i.e i'm passing to b.php. also links are created in foreach loop.
I am trying hard to get this done, but no success yet.
waiting for valuable reply.
Ok, I think I understand...
I think what you need to do is store the current page number as a JavaScript variable. Use the function that is doing the Ajax to update this variable and also update the next/previous links.
Hope this helps.
Update:
On second thoughts, here's a better idea. Having your ajax call directly in your link means you have to put together a url and update it, which is awkward and annoying. This isn't ideal. Instead it is better to store the variables and have some set functions work with them in a set way. So, you could have something like:
<a href="javascript:void(0)" onclick="gotoNextPage()">
Rather than passing them the number of the page to go to, you can store the current page number in a javascript variable and do something like this:
gotoNextPage(){
// lets assume the current page number is stored in a
// variable defined outside of this function called curr_page
curr_page++; // increment the current
call_ajax('user_info.php?pageno='+curr_page);
}
This way the code for the link doesn't ever change.
You can still pass other variables (such as 'order', 'perpage' etc) to gotoNextPage() but you might find you don't need to.
A couple of things to bear in mind:
1. Using jQuery or something similar would probably make things easier for you.
2. Anyone without javascript enabled will not be able to use your site. Consider changing it to something like
<?php
echo '<a href="your_main_page.php?page_number=', ($curr_page + 1), '" onclick="gotoNextPage()">';
?>
This way it would work for via the ajax method but would also work (if not as smoothly and with a page reload) for people without javascript. It's a bit more work for you though...so hat's your choice!
Hope this makes sense. It's been a long day!