MikoLone
03-13-2007, 05:25 PM
I am having all kinds of problems. :) Sorry guys. I am trying to build an AJAX automatic word search javascript. I have basically copied code from a book and tried it out. But I get and error. I will post my code and then explain more.
oHTTPPronounceReq = null;
iMyTimer = null;
category = 'Terminology';
function searchPronunciation(text){
if(iMyTimer != null){
clearTimeout(iMyTimer);
iMyTimer = null;
}
if(!oHTTPPronounceReq){
oHTTPPronounceReq = getXMLHTTPRequest();
}else if(oHTTPPronounceReq.readyState != 0){
oHTTPPronounceReq.abort();
}
var postStr = 't=' + text + '&category=' + category;
oHTTPPronounceReq.open("POST", "Pronunciation.php", true);
oHTTPPronounceReq.onreadystatechange = function (){
if(oHTTPPronounceReq.readyState == 4){
if(oHTTPPronounceReq.status == 200){
var response = oHTTPPronounceReq.responseText;
}
}
}
oHTTPPronounceReq.send(postStr);
iMyTimer = setTimeout(function () {
oHTTPPronounceReq.send(postStr);
}, 500);
}
function getXMLHTTPRequest() {
var requester = false;
try {
requester = new XMLHttpRequest();
}
catch (error) {
var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHTTP"];
for(var i = 0; i< aVersions.length;i++){
try {
requester = new ActiveXObject(aVersions[i]);
}
catch (error) {
continue;
}
}
}
return requester;
}
This is the error that I get
Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://flash.dev.mike/pronunciation/js/test.js :: anonymous :: line 25" data: no]
Source File: http://flash.dev.mike/pronunciation/js/test.js
Line: 25
I have the searchPronunciation firing on the onKeyUp event. I get this when I have typed too fast. If I type slow I don't have this problem.
Also for some strange reason my post str is not being received by my php file. The $_POST variable is empty. :(
Any ideas on what I have done wrong?
Thanks.
Michael
oHTTPPronounceReq = null;
iMyTimer = null;
category = 'Terminology';
function searchPronunciation(text){
if(iMyTimer != null){
clearTimeout(iMyTimer);
iMyTimer = null;
}
if(!oHTTPPronounceReq){
oHTTPPronounceReq = getXMLHTTPRequest();
}else if(oHTTPPronounceReq.readyState != 0){
oHTTPPronounceReq.abort();
}
var postStr = 't=' + text + '&category=' + category;
oHTTPPronounceReq.open("POST", "Pronunciation.php", true);
oHTTPPronounceReq.onreadystatechange = function (){
if(oHTTPPronounceReq.readyState == 4){
if(oHTTPPronounceReq.status == 200){
var response = oHTTPPronounceReq.responseText;
}
}
}
oHTTPPronounceReq.send(postStr);
iMyTimer = setTimeout(function () {
oHTTPPronounceReq.send(postStr);
}, 500);
}
function getXMLHTTPRequest() {
var requester = false;
try {
requester = new XMLHttpRequest();
}
catch (error) {
var aVersions = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp", "Microsoft.XMLHTTP"];
for(var i = 0; i< aVersions.length;i++){
try {
requester = new ActiveXObject(aVersions[i]);
}
catch (error) {
continue;
}
}
}
return requester;
}
This is the error that I get
Error: [Exception... "Component returned failure code: 0x80040111 (NS_ERROR_NOT_AVAILABLE) [nsIXMLHttpRequest.status]" nsresult: "0x80040111 (NS_ERROR_NOT_AVAILABLE)" location: "JS frame :: http://flash.dev.mike/pronunciation/js/test.js :: anonymous :: line 25" data: no]
Source File: http://flash.dev.mike/pronunciation/js/test.js
Line: 25
I have the searchPronunciation firing on the onKeyUp event. I get this when I have typed too fast. If I type slow I don't have this problem.
Also for some strange reason my post str is not being received by my php file. The $_POST variable is empty. :(
Any ideas on what I have done wrong?
Thanks.
Michael