Jump to content

[SOLVED] Ajax mysql


Beffic

Recommended Posts

How can I change the request in here from the chat.txt file to a mysql request?

 

function ajax_read(url) {
if(window.XMLHttpRequest){
	xmlhttp=new XMLHttpRequest();
	if(xmlhttp.overrideMimeType){
		xmlhttp.overrideMimeType('text/xml');
	}
} else if(window.ActiveXObject){
	try{
		xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
	} catch(e) {
		try{
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} catch(e){
		}
	}
}

if(!xmlhttp) {
	alert('Giving up  Cannot create an XMLHTTP instance');
	return false;
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
	document.getElementById("chatwindow").innerHTML = xmlhttp.responseText;

	zeit = new Date(); 
	ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds(); 
	intUpdate = setTimeout("ajax_read('chat.txt?x=" + ms + "')", waittime)
	}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}

Link to comment
Share on other sites

Don't take this the wrong way, but you obviously either have no idea how PHP/AJAX work, or you have no idea how they work together.

 

 

AJAX simply emulates a request to a server and allows you to manipulate the content.  PHP is run 100% (in this context) server side; therefore, it would not make sense to try to put PHP code in JavaScript.  You will need the AJAX script to send the request to a PHP page which will handle the request and return the desired results.

Link to comment
Share on other sites

Your ajax_read function should still work.  You are essentially still reading from a file.  JS doesn't know the difference between a plain text file and a PHP file (for these purposes anyway).  All it knows is that it got back the text that was sent to it.  Therefore, a text file and a PHP file can be requested the same way.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.