AJAX :S
Posted: Thu Jan 01, 2009 9:30 am
Hi!
im here again... i wanted to learn AJAX and after a long time i decided to do so now that i have free time but what do i found:
i made a simple ajax script based on others i have seen... but i don't know why it is not working. It only works when i test it on my local server and with the send method GET and running on firefox not on IE... but when i upload it to my host it doesn't work in any way... Nor post neither get and it tells me Method not allowed i don't know why, i know the server supports ajax cause i have tried another downloaded ajax examples and they did work...
Here is my xhtml:
Here is my php:
i change:
to this:
for POST method...
any ideas??
thx in advance!
im here again... i wanted to learn AJAX and after a long time i decided to do so now that i have free time but what do i found:
i made a simple ajax script based on others i have seen... but i don't know why it is not working. It only works when i test it on my local server and with the send method GET and running on firefox not on IE... but when i upload it to my host it doesn't work in any way... Nor post neither get and it tells me Method not allowed i don't know why, i know the server supports ajax cause i have tried another downloaded ajax examples and they did work...
Here is my xhtml:
Code: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/* Simple AjaxLib
*Original autor: BETA.
*Please beware of stealing.
*Licensed under a Creative Commons by-nc-nd license.
*/
function createAjax(){
try{
// Firefox, Safari, Opera, recent versions of IE
xmlhttp = new XMLHttpRequest();
}catch(err){
try{
//Internet explorer
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}catch(err){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(err){
alert('Your browser does not support AJAX!');
return false;
}
}
}
return xmlhttp;
}
function useAjax(obj,url,vars,method){
var ajax = createAjax();
var objid = document.getElementById(obj);
if(method.toUpperCase() == "POST"){
ajax.open("POST", url, true);
ajax.onreadystatechange = function(){
if (ajax.readyState == 1){
objid.innerHTML = "Loading...";
}else if (ajax.readyState == 4){
if(ajax.status == 200){
objid.innerHTML = ajax.responseText;
}else if(ajax.status == 404){
objid.innerHTML = "URL does not exist!";
}else{
objid.innerHTML = "Error: ".ajax.status;
}
}
}
ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajax.send(vars);
return;
}else{
ajax.open("GET", url, true);
ajax.onreadystatechange = function(){
if (ajax.readyState == 1){
objid.innerHTML = "Loading...";
}else if (ajax.readyState == 4){
if(ajax.status == 200){
objid.innerHTML = ajax.responseText;
}else if(ajax.status == 404){
objid.innerHTML = "URL does not exist!";
}else{
objid.innerHTML = "Error: ".ajax.status;
}
}
}
ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
ajax.send(null);
return;
}
}
</script>
</head>
<body>
<form name="usrform" method="GET" onsubmit="useAjax('divy','ajax.php?txt='+document.getElementById('txt').value,'', 'get')" action="#" enctype="multipart/form-data">
<input id="txt" type="text"/>
<input type="submit" value="Send!"/>
</form>
<div id="divy">
</div>
</body>
</html>Code: Select all
<?php
header('Content-type: text/xml');
print_r($_GET);
print_r($_POST);
?>Code: Select all
<form name="usrform" method="GET" onsubmit="useAjax('divy','ajax.php?txt='+document.getElementById('txt').value,'', 'get')" action="#" enctype="multipart/form-data">Code: Select all
<form name="usrform" method="POST" onsubmit="useAjax('divy','ajax.php',document.getElementById('txt').value, 'post')" action="#" enctype="multipart/form-data">any ideas??
thx in advance!