Sending Arguments To Xmlhttp.onreadystatechange Event
Oct 28, 2005
Hw do I send arguments to an onreadystatefunction when calling a document via xmlhttprequest object. For example,
I want to do something like
function getDoc(url)
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=writeHTML(id);
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function writeHTML(id){
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
document.getElementById(id).innerHTML = xmlhttp.responseText;
}
}
I'm trying to make use of XMLHTTP object, but I've come across a problem. It seems that there is no way to create dynamic array of such XMLHTTP objects (to make several requests) and handle them properly. I was trying to use such code:
The above code would have to be embedded into the PHP file.
how can we go about doing that unobtrusively? Ie by not putting the code into the PHP files how can a different argument be passed to that function depending on what page is loaded?
This is related to the pop-up window. Below is the function related to pop-up window. function openPopUpDetailsMultiple(seqNum ,controllername ) { if (!popUpDetails||popUpDetails.closed) { popUpDetails=window.open("GetSCEventAddData?schandle=<!.schandle>&objID=<!.objID>&seqnum="+seqNum+"&controllername="+controllername+,"popUpDetails","toolbar=1,location=0,scrollbars=1,width=600,height=300,resizable=1,left=200,top=200"); }else{ popUpDetails.focus(); popUpDetails.location="GetSCEventAddData?schandle=<!.schandle>&objID=<!.objID>&seqnum=" + seqNum; } }
The problem I'm facing now is in this piece of code: ><a href=javascript:openPopUpDetailsMultiple('"+ scEv[i].sceSeq+"''"+ scEv[i].sceCntr +"')><img src=images/NsaMoreDetails.gif border=0 height=16 width=16 align=middle alt='View more details'>More details</a></td></tr></table></td></tr></table>"); I do not know how to send these (scEv[i].sceSeq,scEv[i].sceCntr) arguments. What might be the delimiter for these arguments.
I'm use prototype quite a lot for ajax calls, but have always used inline onclicks. I'm trying to be less obtrusive by creating event handlers/listeners.I used to do this with the aid of pHp to place arguments into the function (usually via 'while loop'):
I'm trying to create links that onclick sort a table by title, author, etc. How would I pass an argument to an event handler? Right now, it just executes the sort function. It doesn't wait for me to click the link.
I haven't come across an exampe that would enable me to pass data to my event handler.For example, if I click a button I want it to pass the value of an adjacent text input to my handler.
Im trying to write a code to draw random numbers, like a lottery generator. It will require the user to input amount of numbers per line & choose the amount of numbers. From the numbers the user inputs it will generate random numbers to that guideline.
I have wrote the random number function, that works fine. Im having problems invoking it with ONCLICK event handlers. I cant seem to get the correct arguments. And all i get in return is "undefined"
This is the form for the onclick button <INPUT TYPE = "button" NAME = "drawBalls" VALUE ="Draw the Balls!" ONCLICK = "lotteryForm.drawnNumbersTextBox.value = ">
Now Im not putting up to much code, as its part of an Assignment, I dont want to cheat, i just want to be pointed in the right direction. :(
edited: the first alert has this in the brackets: &l t; i.e. the html code for < but for some reason this foum converts it. and i thought html was off?
I was expecting the above to alert the text in the brackets exactly as written in the code for both divs. However both events alert '<'. Why is that? I want to be able to pass '<' as an agrument to events without being converted, because that is what is happening. How may I prevent it?
I have a site which displays a selection of advert listings. We log the number of clicks each advert receives via ajax requests.The listings link to both internal pages on our site and external pages, hence the ajax - we cannot log the'clicks' by logging the requests on the destination pages as these are not all on our site for us to log. Also, I don't want to potentially get false positives e.g.from bookmarked pages - hence I am logging the actual clicks, not the requests on the destination.
All is OK in most browsers, but there is a problem with Safari (I am running Safari 4.0 on Windows XP running in Virtualbox OSE) but only where the destination is to open in the same window/tab (some listings go to a new window, some don't). I am logging clicks via an ajax request in the onclick event, which is working fine when the listing is to open in a new window, but it appears that when a new window is not to be opened, the ajax never gets sent.A have constructed the following minimal test case:
index.html
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" [code].....
Note the line commented '****' in index.html which cancels the action of the link. When this is not commented out, the ajax request is sent correctly. Without it (the desired situation) the ajax request never gets sent. Its as if Safari saves up the ajax requests to do later, but never sends them as the new page cancels all such 'saved up' actions.I am using the Safari web developer tools, but I have also checked this test case by checking the Apache logs. Note that as a test case I don't pretend that it will work in IE, but it should work in standards compliant browsers and has been tested on Firefox 3.6.6 and Opera 10.6. The Apache logs show that logger.txt is being requested, unless it is already in the browser cache.Possible workarounds I've considered, but would prefer to avoid:
On the site in question the only such links that currently open in the same window are internal, so I do have the option of logging safari clicks by logging these requests as opposed to clicks and checking the http referer on the server side. As this is not a very flexible solution as it relies on these specific circumstances, also relies on all other links successfully making a new window, and furthermore relying on http referer could result in false negatives I'd rather find a solution within the javascript.I haven't checked whether an asynchonous request would work, but I don't wish to do this anyway just in case there is ever a server problem that prevents the response coming back (note that for these purposes the response is actually superfluous - we are sending the server a message but don't need anything back). I also want to avoid the delay in sending the user to the destination - there is no point having to wait for a response we don't need.Lastly, and my prefered workaround unless I can find anything better, is to make Safari (only) open all links in a new window anyway.
So, my boss is obessed with AJAX and is convinced we need to use it for all of our js menus. I've unfortunately run into some issues with the code below.
It's not throwing any errors in IE or FireFox, but it's not working. IE never shows the 'handler' alert, and FireFox shows the 'handler' alert 3 times, but doesn't seem to ever get to readyState 4 to display the 'loaded' alert. Code:
I am trying to pass an argument to a function to process server responses. My original line of code looked like this: [url]
This works well enough as is, but I am trying to pass arguments to the function, and everything I am reading says to contruct the code like this: [url]
Every example I have come across uses this same approach, but I keep getting the error "Expected ';'" pointing to this line and then the code fails to execute. I just cannot see where there is anything missing, and it looks pretty much identical to my examples.
I have also tried replacing the call to the function with the actual code in long-form, and the result is the same.
I'm trying to do use XMLHTTP to do a POST in the following JavaScript snippet.
var xml = new ActiveXObject('Microsoft.XMLHTTP'); xml.open("POST", "http://some/url/", false); xml.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xml.send("username=myusername&password=mypassword"); document.write(xml.responseText);
This works fine in Internet Explorer 6 SP2. However, I would like to use https, rather than http. When I change the URL to https and reload the page, I get an error: "The download of the specified resource has failed". As a test, I tried running the same code in Firefox (changing the first line to "var xml = new XMLHttpRequest()"), and this worked for both http and https perfectly, although using https causes a dialog box to pop up asking the user to accept the SSL certificate. Unfortunately, I really need this to work in IE.
I found a couple of discussions on Usenet about this, but none that seemed to give me a clear answer to this issue. Does anybody know what might be wrong or how I might fix it?
Just playing around with xmlhttp at the moment. I was just wondering if there is any reason (browser compatibility etc) the response data has to be formatted in xml, or can I send csv or whatever else if the handler is up for it?
I've been looking into the possibility of using XMLHTTP for my enterprise application but I still have a question.
When you send the request to the server, how does the server know how to handle the request? (i.e. how do I specify what method to call in my java servlet?)
I'd appreciate any help on this.....I've only got a vaey basic knowledge of javascript and I am fluent in java.
I embedded a javascript in HTML and tried to open the file using mozilla 1.4 it gave me the following exception in the script on clicking the Submit/Next button. IE was able to execute the script
Function defination function evaluate(form)
Line making the call : <INPUT onclick="if (validate(this.form)) evaluate(this.form);" type=button value=Submit/Next name=B1>
I am using AWM menu and there is functon awmCreateMenu() which creates a menu, but exactly not getting the different arguments to this function. How to get meanings of these parameters? Actually I want to activate or open this menu using an short key like shift+MenuName first alphabet eg Shift + A or Alt + A will also do.
Using XMLHTTP and DOM I'm able to load new HTML page content.
I'd now like to load small snippets of javascript with the HTML markup and have that <script> incorporated into the page. If any of the loaded script exists outside a function definition (eg: a call to a function), I'd like that code to be executed as soon as its added to the DOM.
Can anyone suggest the best way to do this? I've Googled but not found anything comprehensive. Do I need to use the eval() method or is there a better way?