473,395 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

ajax readyState 1 wall

gp
This code is stopping ...I can't get past readyState == 1....
for testing purposes my searchDB.php is simply:
<?php
echo "string blahahahahah blahahaha hahahahhb ahaha";
?>

newK is <input idit is dynamically created with php at the time the
form loads...there up to 28 <input>
that will have the google type search suggestion <div>. srchK is the
<div idgenerated for each corresponding <input>

var xhr;

function XHR() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject(
"Microsoft.XMLHTTP");
}
return xhr;
}

function searchDB(newK, srchK) {
var http = XHR();

var str = escape($(newK).value);
http.open('POST', 'http://my.url.here/searchDB.php', true);
http.setRequestHeader("Content-type",
"application/x-www-form-urlencoded; charset=UTF-8");
http.onreadystatechange = handleSearchSuggest(http, newK,
srchK);
http.send(str);
}

function handleSearchSuggest(http, newK, srchK) {
var xhttp = http;

if (xhttp.readyState == 4) {
var ss = $(srchK);
ss.innerHTML = '';
var str = xhttp.responseText;//.split("\n");
var estr = eval(str);
alert (estr);
for (var i=0; i < estr.length - 1; i++ ) {
alert (i);
var suggest = '<div
onmouseover="javascript:suggestOver(this):" ';
suggest += 'onmouseout="javascript:suggestOut(this);"
';
suggest +=
'onclick="javascript:setSearch(this.innerHTML, '+newK+', '+srchK+');"
';
suggest += 'class="suggest_link">' + str[i] + '</div>';
ss.innerHTML += suggest;
}
}

Oct 12 '06 #1
2 22530
What's your question?




gp wrote:
This code is stopping ...I can't get past readyState == 1....
for testing purposes my searchDB.php is simply:
<?php
echo "string blahahahahah blahahaha hahahahhb ahaha";
?>

newK is <input idit is dynamically created with php at the time the
form loads...there up to 28 <input>
that will have the google type search suggestion <div>. srchK is the
<div idgenerated for each corresponding <input>

var xhr;

function XHR() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject(
"Microsoft.XMLHTTP");
}
return xhr;
}

function searchDB(newK, srchK) {
var http = XHR();

var str = escape($(newK).value);
http.open('POST', 'http://my.url.here/searchDB.php', true);
http.setRequestHeader("Content-type",
"application/x-www-form-urlencoded; charset=UTF-8");
http.onreadystatechange = handleSearchSuggest(http, newK,
srchK);
http.send(str);
}

function handleSearchSuggest(http, newK, srchK) {
var xhttp = http;

if (xhttp.readyState == 4) {
var ss = $(srchK);
ss.innerHTML = '';
var str = xhttp.responseText;//.split("\n");
var estr = eval(str);
alert (estr);
for (var i=0; i < estr.length - 1; i++ ) {
alert (i);
var suggest = '<div
onmouseover="javascript:suggestOver(this):" ';
suggest += 'onmouseout="javascript:suggestOut(this);"
';
suggest +=
'onclick="javascript:setSearch(this.innerHTML, '+newK+', '+srchK+');"
';
suggest += 'class="suggest_link">' + str[i] + '</div>';
ss.innerHTML += suggest;
}
}
Oct 12 '06 #2
gp wrote:

[snip]
var xhr;
A global variable to which you assign, and yet return from a function? Odd.
function XHR() {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
xhr = new ActiveXObject(
"Microsoft.XMLHTTP");
You aren't worried about MSIE throwing an exception if ActiveX is
disabled? Consider an alternate implementation - there are examples in
the group archives[1].

[snip]
var str = escape($(newK).value);
You aren't using Prototype, are you?

[snip]
http.onreadystatechange = handleSearchSuggest(http, newK,
srchK);
Here, you are calling the handleSearchSuggest function, and assigning
its return value to the onreadystatechange property. You either need to
assign a reference directly:

http.onreadystatechange = handleSearchSuggest;

and modify the function appropriately, or create another function which
takes its place and called handleSearchSuggest with the appropriate
arguments.

[snip]
var suggest = '<div
onmouseover="javascript:suggestOver(this):" ';
Here, "javascript:" is just a label and is superfluous. In MSIE, it can
be used to switch languages, but unless VBScript has been used (and that
would be odd, on the Web), it's still unnecessary.

[snip]

Mike
[1]
<http://groups.google.co.uk/group/comp.lang.javascript/msg/fa966be4e9ba3986?hl=en>
Oct 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Eric Wallstedt | last post by:
I have a page that "logs" changes made to input fields using ajax to pass data to a cgi. I use POST and it works fine most of the time (all the time in IE). But it fails when I get the data from...
4
by: Frances | last post by:
I literally started learning AJAX just last weekend.. I have this page, http://www.francesdelrio.com/ajax/db2.html, where I'm essentially doing what's here,...
6
by: Nico VanHaaster | last post by:
Hello all, I have run across an issue with IE 6.0+. I have a page that makes an XMLHttpRequest to the webserver to update a report on the page. The first time you hit the refresh report button...
10
by: shankwheat | last post by:
I'm experimenting with using a AJAX style "processing" icon. The process I'm running in the background with xmlHttp is intensive and takes a 5--10 secs to complete. Instead of my processing icon...
5
by: Heofz | last post by:
Hey all, I've been banging my head against a brick wall on this one for the last 12 hours, and the time has come for me to give up and consult the gurus on this one. The below URL contains a...
4
by: slebetman | last post by:
On Jun 5, 9:36 pm, sheldonlg <sheldonlgwrote: You can of course use closure to pass the required parameter: var hideIt; // the variable you wish to pass ajax.onreadystatechange = function () {...
22
by: sheldonlg | last post by:
I am looking for a clean solution to a problem that I solved in, what I call, a "dirty" way. Here is what I want to do. I have a dropdown list. Clicking on an item in the dropdown list invokes...
2
by: mndprasad | last post by:
Hi friends, Am new to AJAX coding, In my program am going to have two texbox which going to implent AJAX from same table. One box is going to retrieve the value of other and vice...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.