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(); } 

http://php.net/manual/en/reserved.variables.get.php


Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

visual studio 2010 - Connect to informix database windows form application -

android - Associate same looper with different threads -