Click here to Skip to main content
15,885,910 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi

I have the following codes:

JavaScript
function addItem(str) {
	if (str=="") {
		document.getElementById("txtHint").innerHTML="";
		return;
	} 
	if (window.XMLHttpRequest) {
		// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	} else { // code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4 && xmlhttp.status==200) {
			document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
		}
	}
	xmlhttp.open("GET","checkinout-actions/add-more-items-code.php?q="+str,true);
	xmlhttp.send();
	window.location.reload();
}


It is working in Google Chrome but the other browsers mentioned in the title it is not working.

Can you please help me out.

Thank you so much!
Posted
Comments
Afzaal Ahmad Zeeshan 9-May-15 2:34am    
Actually it should work. The technologies are standard based and are not a problem for any of the browser. General problems occurring here would be,

1. Your browser is preventing the requests
2. Browser believes that the request is malicious
3. Browser doesn't allow cross-site origin requests and is cancelling the requests

A few of the options would include that you press F12 and debug the application in browser and see which problem occurs. If the event gets raised (ajax request is initiated) then you will get a log, and also you will be able to see what happened.
Michelle Anne E. Rigor 9-May-15 2:58am    
There was no error when I tried F12.

1 solution

Try this :
JavaScript
var request = new XMLHttpRequest();
request.open('GET', "checkinout-actions/add-more-items-code.php?q="+str);

request.onreadystatechange = function () {
    if (request.readyState == 1) { return }
    else if (request.readyState == 4) {
        if (request.status < 400) {
            // do your stuff here
            document.getElementById("txtHint").innerHTML=request.responseText;
        }
        else if (error != null)
            error(request);
    }
};
request.send();
 
Share this answer
 
v2
Comments
Michelle Anne E. Rigor 9-May-15 2:57am    
I do not understand the code. how will the php page be opened?
Mehdi Gholam 9-May-15 3:03am    
See the updated solution.
Michelle Anne E. Rigor 9-May-15 3:10am    
The codes works but the page does not seem to update after I change the value. The codes are connected to a dropdown/select. Then when the value of the select changes the page should update.
Mehdi Gholam 9-May-15 3:13am    
Try debugging your js under chrome to see what (not)is happening.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900