Guest FirefoxRocks Posted July 15, 2009 Share Posted July 15, 2009 I'm using AJAX in my application to get some subcategories information. I would like to specify the ID of where to return the data to be flexible with the function. I don't know how to do this, I tried adding parenthesis on the function but that broke the functionality.Here is my JavaScript code: var xmlhttp;function getRows(cat, ele){ xmlhttp = new GetXmlHttpObject(); if (xmlhttp==null){ return; } if(cat==="global") { $("#"+ele).html("<option>(global)</option>"); return; } var url="SOMEPAGE.php" + "?cat=" + cat + "&sid=" + Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null);}function stateChanged(){ if (xmlhttp.readyState===4){ $("#assoc_table_item").html(xmlhttp.responseText); }} The variable ele is the ID of the element I want to return the server response to. I don't know how to pass this variable to the stateChanged function, where I can just modify 1 line. With the code I have right now I have to write the stateChanged() function each time I want to change the ID of the element.I tried changing xmlhttp.onreadystatechange=stateChanged; toxmlhttp.onreadystatechange=stateChanged(ele); but it breaks the function.How do I do this? Link to comment Share on other sites More sharing options...
justsomeguy Posted July 15, 2009 Share Posted July 15, 2009 xmlhttp.onreadystatechange= function() { stateChanged(ele); }; Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 15, 2009 Share Posted July 15, 2009 That seems to make sense, but now...Firebug output: onreadystatechange FAILS Syntax error, unrecognized expression: #[object Event] Syntax error, unrecognized expression: #[object Event] [xpconnect wrapped nsIDOMEventListener]EDIT: Never mind, I passed the variable too many times. I feel like an idiot in both cases . Thanks for the help. Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted July 15, 2009 Share Posted July 15, 2009 ~ Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.