top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

PHP side code for jQuery

+1 vote
294 views

I use following code for jQuery.ajax to call php.

$.ajax('myserver.php")

It seems that one php file only work for one jquery ajax code, Is it possible to have more than one function or one return different result in one php file?

Your help is greatly appreciated,

posted May 19, 2014 by Honey

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+2 votes

You could either send information about which function you would like to call on the url parameter ($_GET)

$.ajax('myserver.php?function=ajaxRetrieveData');

or adding into data object ($_GET or $_POST) :

$.ajax({
 type: "POST",
 url: "myserver.php",
 data: { function: 'ajaxRetrieveData' }
});

and then using a router to find the function

myserver.php
$function = $_POST['function'];
$object->$function();

Please, do not use this code without properly validation.

answer May 19, 2014 by Majula Joshi
+1 vote

If you use a framework like code igniter then you can define a single php file in which you can have separate controller functions which can act as different url parts for your different ajax calls.

CodeIgniter is a MVC framework and there are many MVC frameworks which offer the same feature.

answer May 20, 2014 by Shyam Purkayastha
Similar Questions
+2 votes

I am implementing a feature in QueryHome itself so thought what could be the best way to implement and found the best way could be to get the help people. Following is what I am trying to do -

  1. I have a form with multiple field (say 10 fields)
  2. For two fields I want to implement autocomplete feature.
  3. Once user enters 3 characters autocomplete should get hit after that on each character typed..
  4. A PHP function should be called which will set json_encode to populate the result.

Any pointer...

+1 vote

I have a POST form and action itself like following

I want to show success message when POST complete or error message if there is any. I would like to know are there any property or global variable I can check to show message to users. If not, it seems that the only solution is jQuery, since it has success function that jQuery call after POST.

–1 vote

I want to display the number of views of my homepage and continuously increase the views whenever a user opens that page. How to achieve this using PHP and MYSQL?

...