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
https://forums.phpfreaks.com/topic/133401-solved-ajax-mysql/
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
https://forums.phpfreaks.com/topic/133401-solved-ajax-mysql/#findComment-694912
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
https://forums.phpfreaks.com/topic/133401-solved-ajax-mysql/#findComment-696366
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.