javascript - Target a certain PHP function with $.ajax -
hey guys have scenario,
i want use ajax $.get method target php function in separate php file. not sure syntax.
the javascript
function all(){ $.get({ url: "functions.php function ", success: function success(data){ paint(data) }, datatype: "html" }); });
function.php
<?php function helloworld(){ echo "hello world"; }; function hellomars(){ echo "hello mars"; };
any appreciated
pass variable in data
attribute or url query string, , in php script, choose function based on variable.
$.get({ url: "functions.php", data: { "vname": "something" }, success: function success(data){ paint(data) }, datatype: "html" });
http://api.jquery.com/jquery.get/
php:
if ($_get["vname"] == "something") { helloworld(); } else { hellomars(); }
Comments
Post a Comment