Help with XMLHttpRequest object

Hi.

I am having difficulties using a XMLHttpRequest object. I want the response for a php script, “download.php”, to be loaded into a div “p2”.

Javascript | http://pastebin.com/7BvzmEpY

I am using mod_rewrite to be able to call the download.php as download/parameter. Before going any further, it needs to be noted that I have combined the use of an appended GET variable, whilst sending the request as a POST request, is this possible? (It is not necessary, I merely want to try)

For the moment I am trying to get the ondownloadrequest function to work, anything simple I have overlooked?

I should know this, embarassing.

You need to make XMLHInit return the XHR object. I’d also choose better names for your functions and variables. Try not to mix upper and lower case so much and just make them simpler but still easy to identify what they are for.

I don’t think there’s anything wrong with making a POST request along with GET stuff in the query string.

Above all, you need to learn to debug this sort of thing yourself. Go through the entire procedure step by step, and use alert or console.log() to check that things are being defined, that variables hold the values they should be holding, and so on. You’ll probably find that your JS console is showing errors anyway, due to Passw_XMLHttpRequest being undefined in the ondownloadrequest function. If you have not used Firebug before, I strongly recommend you use it and become familiar with it, at the very least with the console’s ability to show you errors.

Thank you. I know about Firebug, for reasons I do not recall I couldn’t install it the previous time I tried. This time it worked though. It reports the error you mentioned.

I have tried (with questionable attentiveness) to debug it with “alert” but didn’t catch the issue I should have catched. And I’d say I have fairly good practice in debugging in general. The XMLHInit function was added as an afterthought because the code did not work in a previous revision, so it is likely there are more things to debug. I will definitely try the console.log() function with Firebug.

P.S. And certainly, I’l clean up the names.

Your code will not work because when you define Passw_XMLHttpRequest, it is local to the function XMLHInit. Therefore it will not be available in your ondownloadrequest function.

You need to make XMLHInit return the XHR object. I’d also choose better names for your functions and variables. Try not to mix upper and lower case so much and just make them simpler but still easy to identify what they are for.

I don’t think there’s anything wrong with making a POST request along with GET stuff in the query string.

Above all, you need to learn to debug this sort of thing yourself. Go through the entire procedure step by step, and use alert or console.log() to check that things are being defined, that variables hold the values they should be holding, and so on. You’ll probably find that your JS console is showing errors anyway, due to Passw_XMLHttpRequest being undefined in the ondownloadrequest function. If you have not used Firebug before, I strongly recommend you use it and become familiar with it, at the very least with the console’s ability to show you errors.