Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Ajax Question

Featured Replies

Sorry for double posting!

 

 

Hi all,

 

Ok so I have a piee of Ajax in my site thats baffling me. Im totally new to Ajax so any help will be much appreciated!

 

 

 

1) I have a form that passes a variable to the ajax function and works perfectly (as below).

 

<form name='myForm'>

<input type="hidden" id='id' name='id' value='<? echo $id; ?>' />

<input type='button' onclick='ajaxFunction()' value='Query MySQL' />

</form>

 

 

 

2) The function passes the variable to the desired page (includes/process_ajax_gallery_request.php) and works perfectly.

 

 

3) In the file (includes/process_ajax_gallery_request.php) i have a php function that querys the database and outputs some images.

 

 

 

4) Heres the prob: the output happens and is sent to "ajaxDiv" (as you will see below) but I cannot see anything on screen! I checked the source code of the HTML page and i can see that its there (ie <img src=.......>) but I cant see anything on the screen.

 

I done a little research with no luck but is it something to do with the DOM or something? Totally new to this!

 

Heres the Ajax function that takes care of it all:

 

 

 

function ajaxFunction(){

var ajaxRequest;

 

try{

ajaxRequest = new XMLHttpRequest();

} catch (e){

try{

ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");

} catch (e) {

try{

ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");

} catch (e){

alert("Your browser broke!");

return false;

}

}

}

 

ajaxRequest.onreadystatechange = function(){

if(ajaxRequest.readyState == 4){

var ajaxDisplay = document.getElementById('ajaxdiv');

ajaxDisplay.innerHTML = ajaxRequest.responseText;

}

}

var id = document.getElementById('id').value;

var queryString = "?id=" + id;

ajaxRequest.open("GET", "includes/process_ajax_gallery_request.php" + queryString, true);

ajaxRequest.send(null);

}

 

 

 

Do I need to do something with this?

ajaxDisplay.innerHTML = ajaxRequest.responseText;

 

 

Any help is much appreciated.

 

Thank you in advance and for reading this far!

 

Wayne.

Hi!

 

@waynef

 

Instead of using innerHTML, try to create the element and add it as a child node within ajaxDisplay. Sometimes browser security can keep you from doing stuff, so try the same example by having the PHP script return a simple text string to make sure it works.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.