Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Help 

AJAX w/ Javacript help :3

I'm trying to query a database via ajax with javascript, but it simply won't work!

PHP Code

<?php 
xmlhttp 
= new XMLHttpRequest();
xmlhttp.onreadystatechange = function()
{
    if(
xmlhttp.readyState == 4 && xmlhttp.status == 200)
    {
        
document.getElementById("sb").innerHTML = xmlhttp.responseText;
    }
}
xmlhttp.open("GET", "send.php?name=cathal&message=test", true);
xmlhttp.send(); 

I tried running the send.php script manually and the database updated fine, so that script is not the problem. Furthermore, when I load the broken script and check the javascript console, there's no errors;

Code
[21:14:36.202] POST http://localhost/xxxx/xxxx/ [HTTP/1.1 200 OK 11ms]
[21:14:36.294] GET http://localhost/xxxx/xxxx/refresh.php [HTTP/1.1 200 OK 11ms]

However, notice how there's no request for send.php? It's just not sending, and I can't figure out why.

Furthermore, the request.php ran successfully, and I'm using (word for word) the exact same code to make that request, the only difference being the actual URL, obviously.

Finally, I set up flags at various points throughout the script, all of which executed without fault. Dafuuuq?

EDIT, nothing in the apache logs either.
The code you provided seems to be working fine for me.

I know you said it's not send.php, so maybe you have got the GET 'name' or 'message' different names in your send.php ?
That code works fine for me :/
(Dec 17, 2013 10:42 AM)stevenrfc Wrote:  The code you provided seems to be working fine for me.

I know you said it's not send.php, so maybe you have got the GET 'name' or 'message' different names in your send.php ?
That code works fine for me :/

Thanks for trying, but I found a far simpler solution using jQuery which works flawlessly;

PHP Code

<?php 
$.ajax({
    
url: "send.php",
    
type:"get",
    
data:{name: name, message: message},
    
success: function(response)
    {
        
//
    
},
    
error: function(error)
    {
        
//
    
}
});
loadShouts(); 


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Help] by .eXeJul 23, 2018 03:48 AM 7 142 Jul 23, 2018 03:48 AM
Last Post: .eXe
[Help] by .eXeJul 20, 2018 01:33 PM 0 74 Jul 20, 2018 01:33 PM
Last Post: .eXe
[Help] by Exeption™Jul 4, 2017 08:32 AM 7 254 Jul 4, 2017 08:32 AM
Last Post: Exeption™