Skip to content
Advertisement

How To Target A Specific PHP Function Using Ajax

I am creating a simple comment program. i want to use ajax to refresh the comments and total number of comments. Keeping both functions in a single file is not working for me.

here is my code:

HTML:

JavaScript

PHP: include.php

JavaScript

AJAX:

JavaScript

Advertisement

Answer

Set the PHP to process a named POST item and use switch to determine which function to use:

JavaScript

In your javascript set the same parameter in each request but with a different value: data:{cmd:'banana'}, etc

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement