acidpunk Posted August 12, 2012 Share Posted August 12, 2012 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! Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/ Share on other sites More sharing options...
maxudaskin Posted August 12, 2012 Share Posted August 12, 2012 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..." />. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368799 Share on other sites More sharing options...
acidpunk Posted August 12, 2012 Author Share Posted August 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368849 Share on other sites More sharing options...
acidpunk Posted August 12, 2012 Author Share Posted August 12, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1368850 Share on other sites More sharing options...
jazzman1 Posted August 13, 2012 Share Posted August 13, 2012 Have you tried dumping the page variable? After first a curly bracket put in - alert (page) . Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369073 Share on other sites More sharing options...
acidpunk Posted August 13, 2012 Author Share Posted August 13, 2012 nope, I really don't know what I'm doing, thats why i'm trying to ask for some help. I'm very new to ajax. i'm basically trying to get guided through building this. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369143 Share on other sites More sharing options...
acidpunk Posted August 13, 2012 Author Share Posted August 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369147 Share on other sites More sharing options...
jazzman1 Posted August 13, 2012 Share Posted August 13, 2012 I really want to help you, but if you don't have an idea how ajax works, you could start to learn some tutorial on the web. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369152 Share on other sites More sharing options...
acidpunk Posted August 13, 2012 Author Share Posted August 13, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369162 Share on other sites More sharing options...
jazzman1 Posted August 13, 2012 Share Posted August 13, 2012 Okay, in this case post all related code. Quote Link to comment https://forums.phpfreaks.com/topic/266970-php-ajax-help/#findComment-1369164 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.