Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript AJAX POST does not work for mysqli

Hi, Geniuses:
I have followed the instructions on this page using a database on my machine.
Everything works fine.
However, the code does not work when I change all "GET"s to "POST"s and change
xmlhttp.open("GET","getuser.php?q="+str,true); xmlhttp.send();
to
xmlhttp.open("POST","getuser.php",true); xmlhttp.send("q="+str);
So what do I miss?
 
Last edited:
Thanks a lot, cbreemer.
I changed $q = intval($_POST['q']) to $q = intval($_REQUEST['q']), it works immediately.
When I changed back to intval($_POST['q']), it works too. Quite strange, but works anyway.
Thanks again.
Hm... weird. Perhaps your page needed refreshing. Anyway, I think we've cracked this one, right ?
 
Hm, strange, I did test it. Admittedly, I used a different W3C example : https://www.w3schools.com/xml/ajax_php.asp
This uses GET and I got it to work with POST by making your changes (which did not work), then adding my line (which made it work).
Hi, cbreemer.
I tried to move function showUser(str) out of the HTML file, and put it in a ajax.js file. Then I put a line <script type="text/javascript" src="ajax.js"></script> to refer to it. The entire set immediately stops working. So what do I miss here?
 
I tried to move function showUser(str) out of the HTML file, and put it in a ajax.js file. Then I put a line <script type="text/javascript" src="ajax.js"></script> to refer to it. The entire set immediately stops working. So what do I miss here?
That looks like it should work. But are you sure that js file is in the same directory as the html file ? And have you started the debugger and looked for errors, in this case specifically in the Network tab ?

EDIT - Actually this should have been a new thread. It has nothing to do with the current issue which has been marked as solved.
 
Last edited by a moderator:
That looks like it should work. But are you sure that js file is in the same directory as the html file ? And have you started the debugger and looked for errors, in this case specifically in the Network tab ?

EDIT - Actually this should have been a new thread. It has nothing to do with the current issue which has been marked as solved.
Thanks, cbreemer, for replying.
Yes, my ajax.js is in the same directory as the HTML file. I will debug it and post it on a new thread.
 

New Threads

Buy us a coffee!

Back
Top Bottom