Jump to content

php, ajax help


acidpunk

Recommended Posts

I don't know how to ask this, but i'm going to try, so bare with me please.

 

I'm trying to send an ajax request to a page, like page.php?page=1

 

But each time I move pages, say I click next page, it brings me to page.php?page=2. During that switch, I'm trying to load an image, using AJAX. So the page never switches from page.php?page=1 to page.php?page=2. Understand my question? I wan't to click the next page link, and automatically have the page change using an ajax request, and load that image for the page=2 page.

 

Please, if anyone can help me, I would be so much greatly appreciated. I've been trying this for days now, i'm stumped. I don't know where to go, i'm just starting with the ajax request. Do i use .load, get, json. help please!

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/
Share on other sites

Correct me if I'm wrong, but what I think you're trying to do is have a loading image while AJAX is fetching the next page.

 

If you post your AJAX javascript code, I can show you exactly what to do, but in the mean time, in the function that fetches the PHP page data, change the element innerHTML to <img src="path/to/loading_image.gif" height="100 width="100" alt="Loading..." />.

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368799
Share on other sites

function addroom(page) {
    var ajaxRequest;  // The variable that makes Ajax possible!

    try {
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer Browsers
        try {
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function() {
        if (ajaxRequest.readyState == 4) {
        }
    }
    ajaxRequest.open("GET", "page?page=" + page, true);
    ajaxRequest.send(null);
    setTimeout("addroom()", 30);
}

 

something like that? on my page.php?page=page script, the php, I'm going to call the $_GET data in an array, select it, and echo out the image based off what page i'm on. And that ajax request should call for addroom(); and create my images? right? This is what i've been trying to do. lol. nothing works though.

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368849
Share on other sites

And no, not a loading image. An image that is already in a table within my database, which wants to be shown every time a user moves. It is for an RPG. basically a world, with a (east, west, south, north) direction base. The user is moving image frames each time they move a direction.

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368850
Share on other sites

ill try to explain it again.

 

 

link: (page.php?page=2)

image below:

 

[]-[0]-[]-[]

 

my direstions:

(left) or (right)

 

lets say, we click (right)

 

 

new link would be page.php?page=3

my image would now change to this:

 

[]-[]-[0]-[]

 

my directions:

(left) or (right)

 

 

I want to automatically load the page, so the page never refreshes, and the new image loads, without actually switching the page to page.php?page=2 to page.php?page=3. I wan't to automatically load it.

 

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369147
Share on other sites

I understand how it works, I just need someone to guide me and explain to me what I need. I understand the script I posted in the beginning is sending a request to page.php, in my page.php i'm getting the $_GET data, which grabs the page.php?page= number, i just don't know how to execute all of this together..

 

thats the whole point of asking for help.

Link to comment
https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369162
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.