Wednesday, March 14, 2012

Call PHP Function In JavaScript Using Ajax

how to call php function from javascript function

1. create Folder on WWW Or htdocs (on your computer)

2. create index.php page on your folder and paste this code


<script src=""></script> 

function addsearchproduct(x){  
// this is JavaScript  function  

  type: 'POST',
  url: "function.php?f=phpFunction&p="+x, 

       // call php function , phpFunction=function Name , x= parameter 
  data: {},
  success: function(data1){


<input type="button" value="call Php Function" onclick="addsearchproduct('pass value');"  />


3. create function.php  page on your folder and paste this code


if(function_exists($_GET['f'])) { // get function name and parameter  $_GET['f']($_GET["p"]);
} else {
'Method Not Exist';

phpFunction($val=''){      // create php function here  
echo $val ;

4. run your index.php file



  1. Aw, this was a really nice post. Spending some time and actual
    effort to generate a superb article… but what can
    I say… I procrastinate a whole lot and don't manage to get nearly anything done.

    my web page - pikavippi 200e

  2. Article writing is also a excitement, if you be acquainted with afterward you can
    write if not it is difficult to write.

    Take a look at my webpage visit the following web site

  3. for me it is displaying "Method Not Exist" message. it is not showing any method name. could please suggest me, how to call php function in javascript

  4. Fantastic post however I was wondering if you could write a litte more on this subject?
    I'd be very grateful if you could elaborate a little bit further. Many thanks!

    Look into my web site:

  5. It's not my first time to pay a visit this website, i am visiting this web site dailly and obtain good information from here every day.

    Also visit my web page - Buy Xtrasize

  6. I've been browsing online more than 3 hours today, yet I
    never found any interesting article like yours. It's pretty
    worth enough for me. Personally, if all webmasters and
    bloggers made good content as you did, the net will be much more useful than ever before.

    Look at my web page Chicago SEO Services

  7. nice "workaround" - thanks

  8. Very interesting critique

    Also visit my website ... hytera accessories

  9. Somebody necessaгily һelp to make severely posts І'ԁ state.
    That іs the fіrst tіme I frequented үour website рage and to thiѕ point?

    I amazed wіth tһe reѕearch үou made to create tһis actual put ᥙp incredible.
    Magnificent process!

  10. Keep on writing, great job!


If you Satisfied , Please Leave a comment