javascript

Started by actionman, April 22, 2013, 10:04:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

actionman

now im well lost how do i get the ajax request stuff - sorry to be so dumb but Java is new to me and im lost

im guessing it would be something simple like

$reel1 = $.res1

etc etc

but knowing me probably not

thanks to all that have helped so far

ShadoW69

my suggestion is to learn jquery, its cross-browser compatible and easy to use. so instead of having alot of line you can have just a couple.
Code (javascript) Select

$(document).ready(function(){
    var res1 = win[a.pos],
        res2 = win[b.pos],
        res3 = win[c.pos],
        data = res1 + res2 + res3;
    $.post('result.php',{ result : data }, function(response){
        console.log(response); // DISPLAY IN CONSOLE
        $('#suggestion').html(response); // DISPLAY IN BROWSER
    });
});


for much complex ajax request you can use the $.ajax method. this is just the tip of the ice... :)
this is the same what you posted just cleaner, and im guessing win array is already defined and populated, the object as well with the pos property
Code (javascript) Select

function printResult() {
var res1 = win[a.pos],
res2 = win[b.pos],
res3 = win[c.pos],
data = "result=" + res1 + res2 + res3,
xhr;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open("POST", "result.php", true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                   
xhr.send(data);
xhr.onreadystatechange = function () { //anonymous function
if (xhr.readyState == 4) { 
if (xhr.status == 200) { 
document.getElementById("suggestion").innerHTML = xhr.responseText; 
} else { 
alert('There was a problem with the request.'); 

}
};
}


one thing to note, which is really important, is DON`T SPIN AND POST RESULTS... data can me manipulated this way very easily, by making custom request to your result parser... the best thing to do is make a request to get the data for the spin POST /get_spin_result.php -> data -> show in browser through javascript.
if i where doing this i`d be doing it somewhat like this
press button to start spinning ( while the slots spin)
POST /get_spin.php -> the results [data]
data -> stop spinner 1 at data.first_spin [not actual property]
data -> stop spinner 2 at data.second_spin [not actual property]
data -> stop spinner 3 at data.third_spin [not actual property]
and you`ll need to have a 4th property in the returned data ex. result, its not a must cuz you can sum it up with javascript as well but its better...
getElement..('suggetion') -> display result...

i hope you kind of understood what i`m talking about...
cheers

actionman

i am not lucking to go to u232 till next either i move servers or i set up another site, but thanks for taking the time to help

actionman

i am using centos6 - but got so far following a website how to do it and then wham no more operating system lol - luckily it was a fresh install lol so reformatted again lol


cm27

what os are you trying to get going ?
Never fall to those that just sit there.. Always look for the way to the top even if you have to code it your self and mistakes and all... quote from BonZO...

actionman


Mindless

#6
Speak to the right people here and they'll help with memcache install  mate.

actionman

thanks m8 - good luck with your new stuff - i did try and upgrade to u232 but i couldnt figure out how to install memcache and i have the attention of a goldfish according to my missus lol - so gave up and gone back to tbdev lol

will await replies from others.

Cheers

Mindless

Quite a few on here are good with js so thats cool, I'm no really sure whats the actual answer here due to application, its hard to visualize what your testing, I'm up to my neck with new code right now so heads all over the shop, im sure in this case it will be done using html, so it will be a class id or something on result.php that will pull that, but wait for more replys mate.

actionman

Hi mindless

yes its javascript m8 - but this is about as much knowledge of javascript - (think i need to go back to school lol)

so apologies if i come across stupid but i dont know how to use $_GET from this .js file

just wondered if some kind people here could give me the head start i need

Thanks for the reply

Actionman


Mindless

Is that javascript to post data ? Have you been testing with using $_GET to pull on a while loop or what ever your doing with it ?

actionman

Hi all

i am currently working on javascript slots game - i have managed so far to get the game to spin etc, i have edited the javascript to post the results in a file called results.php (google helped me with this part - but now come stuck) now heres my issue, the results page controls the winning and loosing etc (or will do) by adding or deducting seedbonus points based on the results there are 6 images and if they get three ina row they get between 200 and 800 points depending on the result displayed. and also a small win for 2 in a row.

the js code that does majoriy of the niggly bits is below

Code (javascript) Select
function printResult() {
        var res1 = win[a.pos];
var res2 = win[b.pos];
var res3 = win[c.pos];
var xhr;
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE 8 and older
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
var data = "result=" + res1 + res2 + res3; 
xhr.open("POST", "result.php", true);   
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");                   
xhr.send(data);
xhr.onreadystatechange = display_data; 
function display_data() { 
if (xhr.readyState == 4) { 
if (xhr.status == 200) { 
document.getElementById("suggestion").innerHTML = xhr.responseText; 
} else { 
alert('There was a problem with the request.'); 


}
}


how can i get a results php to read the results from the above???

any help is appreciated