call php function with arguments using Jquery

You can't call a PHP function directly from an AJAX call, but you can do this:

PHP:

<? php 
    function func1($data){
        return $data+1;
    }

    if (isset($_POST['callFunc1'])) {
        echo func1($_POST['callFunc1']);
    }
?>

JS:

$.ajax({
    url: 'myFunctions.php',
    type: 'post',
    data: { "callFunc1": "1"},
    success: function(response) { alert(response); }
});

You should call your php script through an ajax request, using jQuery like:

Javascript:

$.ajax({
  url: "script.php",
  data: { param1: "value1", param2: "value2" },
  type: "GET",
  context: document.body
}).done(function() {
  // your code goes here
});

You could give your parameters through data property of ajax object.

Php

// you can do isset check before 
$param1 = $_GET['param1'];
$param2 = $_GET['param2'];

// validate // sanitize // save to db // blah blah // do something with params

More information you could get from jQuery.ajax() function description from http://api.jquery.com/jQuery.ajax/

Tags:

Php

Ajax

Jquery