# Ajax...



## aximbigfan (Mar 18, 2008)

I have been to 3 different forums now. Every time I post this, someone says "O LOL, that not right, try this script lol!!!!" and then I try it, it doesn't work, and that person never shows up again. 

Can some one, anyone PLEASE HELP ME?!?!?!

Ok...

I have a form (called "form") and a textbox in that form, called "string".

I want to send the contents of string out, with a few other hidden fields, an then write the result in document.form.string.value.

I have this:


```
var http = \"\";

function ajax()
{
var http;

try
{
http = new XMLHttpRequest;
}
catch (e)
{
try
{
http = new ActiveXObject(\"Msxml2.XMLHTTP\");
}
catch (e)
{
try
{
http = new ActiveXObject(\"Microsoft.XMLHTTP\");
}
catch (e)
{
alert(\"AJAX error!\");
return;
}

}
}




http.onreadystatechange = function()
{
if (http.readystate == 4)
{
if (http.status == 200)
{
alert('test');
document.form.string.value = http.responceText;
}
else
{
alert(\"AJAX error!\");
}

}
}


var str = \"mode=\" + document.form.mode.value;
str    += \"&string=\" + document.form.string.value;
str    += \"&key=\" + document.form.key.value;
str    += \"&find=\" + document.form.find.value;
str    += \"&replace=\" + document.form.replace.value;
str    += \"&gen=\" + document.form.gen.value;

http.open(\"POST\",\"index.php\", true);
http.setRequestHeader(\"content-type\",\"application/x-www-form-urlencoded\");
http.send(str);
}
```

..but it does not work. Why?

Can someone please help me?!

Chris


----------



## Kreij (Mar 18, 2008)

What does the code do when you run it? Throw an error or something?


----------



## W1zzard (Mar 18, 2008)

use the firefox script debugger (+ firebug plugin)

you know that ajax needs an url to work with?


----------



## aximbigfan (Mar 18, 2008)

W1zzard said:


> use the firefox script debugger (+ firebug plugin)
> 
> you know that ajax needs an url to work with?



Look at the bottom.

I'll try that.

the script does nothing when executed, it shows no errors in the error log.

Chris


----------



## W1zzard (Mar 19, 2008)

you http object is only instantiated inside the function and the variable http lives only inside the function. you can't just access it from the outside


----------

