Closed
Bug 286653
Opened 20 years ago
Closed 20 years ago
Passing parameters to XMLHttpRequest.onreadystatechange callback breaks scripts
Categories
(Core :: DOM: UI Events & Focus Handling, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: miken32, Unassigned)
Details
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.6) Gecko/20050225 Firefox/1.0.1 Using the basic Apple XMLHttpRequest example at http://developer.apple.com/internet/webcontent/xmlhttpreq.html as a template, I was trying to pass a variable to the onreadystatechange callback function, like so: req=new XMLHttpRequest; req.onreadystatechange=processReqChange(foo); This would not work. Some debugging in processReqChange determined that req.readyState was not advancing beyond 0 (uninitialized.) Simply removing the parameter foo from the callback declaration fixed it up just fine and let req.readyState advance all the way to 4: req=new XMLHttpRequest; req.onreadystatechange=processReqChange; I couldn't find any formal documentation on XMLHttpRequest, so I'm not entirely sure if this is the wrong way to do it, but it seemed like a bug to me. A fairly simple workaround is to pass the data into the PHP script as a GET variable and have it spit it out in the XML data. Reproducible: Always Steps to Reproduce:
Comment 1•20 years ago
|
||
req.onreadystatechange=processReqChange(foo) does not assign a reference to the function processReqChange to req.onreadystatechange but instead calls processReqChange with argument foo and assigns the return value to reg.onreadystatechange. Without a testcase, I would be inclined to mark this invalid. Please attach your example using "Create a New Attachment" link.
| Reporter | ||
Comment 2•20 years ago
|
||
Ok, didn't realize that the function would actually be called, and it's value returned. I was thinking, as you said, that it was assigning a reference. Sorry for the bugspam!
Status: UNCONFIRMED → RESOLVED
Closed: 20 years ago
Resolution: --- → INVALID
Updated•6 years ago
|
Component: Event Handling → User events and focus handling
You need to log in
before you can comment on or make changes to this bug.
Description
•