0

I know little of Javascript but have managed to assemble a code for an ajax request on my web site but now find it is only working on Mozilla/Firefox. My code is:

    function ajaxFunction(char){
    var ajaxRequest;  
    try{
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Your browser broke!");
                return false;
            }
        }
    }
    ajaxRequest.onreadystatechange = function(){
        if(ajaxRequest.readyState == 4){
        if(this.status !==200){
        **alert("Error: Status '+this.status+' returned.");**
    }else{
            document.getElementById('directory').innerHTML=   ajaxRequest.responseText;
            }
        }
    }
    var namevalue=char
    ajaxRequest.open("GET", "../directory pagtestAug.php?name="+namevalue, true);
    ajaxRequest.send(null); 
}

I am also making use of: src="//ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js">
(although I am not sure what this does - I am finding it difficult to find javascript tuition beyond the very basic)

The response is Error :Status'+this.status+' returned.

I have seen many posts on the 200 status but none on what to do if the server does not respond. Is there another code to use or a different one for each browser ? Thank you for taking the trouble to read this (and reply, please)

Knu
  • 14,012
  • 5
  • 54
  • 86
Albireo
  • 1
  • 2
  • Since you have jQuery, I suggest looking into [`$.ajax()`](http://api.jquery.com/jquery.ajax/). – imtheman Jul 07 '16 at 23:05
  • What are those `**`? Were you trying to comment that line? – Knu Jul 07 '16 at 23:10
  • 1
    Your quotes on the alert are mismatched. Change to "Error: Status " + this.status + " returned." to actually get a status code. – T. B. Jul 07 '16 at 23:11
  • @ T.B Excellent comment. I amended the quotes and received an error code. With that information I was able to change a corrupt .js file and the pages are now correctly displayed in the 5 browsers mentioned. – Albireo Jul 09 '16 at 19:27

1 Answers1

0

If by "works in Mozilla only" you mean it doesn't work in chrome, check this link and this link

Basically you have to start chrome with the correct parameters to allow it to access local files.

Community
  • 1
  • 1
Makketronix
  • 1,131
  • 1
  • 8
  • 28
  • I note you comment on Chrome and am looking into it, but as I said above the fault appears to have corrected without making these changes. – Albireo Jul 09 '16 at 19:37