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


index.php

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 



<script>
function addsearchproduct(x){  
// this is JavaScript  function  


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

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

}
</script>

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

 



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

 function.php 

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


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



4. run your index.php file



 

Comments

  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

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  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: http://nitrofocusfacts.com

    ReplyDelete
  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

    ReplyDelete
  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

    ReplyDelete
  7. nice "workaround" - thanks

    ReplyDelete
  8. Very interesting critique

    Also visit my website ... hytera accessories

    ReplyDelete
  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!

    ReplyDelete
  10. Keep on writing, great job!

    ReplyDelete
  11. Hello there! This is my first comment here so I just wanted to give a quick shout out and say I really
    enjoy reading your posts. Can you recommend any other blogs/websites/forums that deal
    with the same topics? Thank you!

    ReplyDelete
  12. Thanks for a marvelous posting! I actually enjoyed reading it, you will
    be a great author.I will always bookmark your blog and
    will often come back very soon. I want to encourage yourself to continue your great
    work, have a nice evening!

    ReplyDelete
  13. Thank you for sharing your thoughts. I really appreciate your efforts and I will
    be waiting for your next write ups thank you once again.

    ReplyDelete
  14. What's up, all is going sound here and ofcourse every one
    is sharing data, that's actually good, keep up writing.

    ReplyDelete
  15. hùa theo
    dữ
    hồ nước
    bậc nhất
    Bạc
    đình hoãn
    hội đàm
    giới trẻ
    bao bọc
    bắt buộc
    phong cách
    tiết lộ
    hiện nay
    thiết kế
    quanh đó
    ngoài
    bí quyết
    xem nhẹ
    bố trí
    bởi thế
    bớt xén
    kềnh càng
    bước đột phá
    buôn bán
    quý khách
    những
    mẫu
    căn bản
    xuất xứ
    cần phải có
    chu đáo
    cắn
    cạnh tranh
    cáu
    vững chắc
    loại vải
    phân phối
    chi phí
    yếu tố
    hàng hiệu
    sắm
    không thấm nước
    lưu ý
    lưu ý
    di chuyển
    chuyên dụng cho
    xây dựng thương hiệu

    kỹ thuật
    công ty
    cộng
    liên hệ
    vô cùng
    mỉm cười
    cứu
    nhiều
    rất nhiều
    mọi
    đặc trưng
    dại dột
    đam mê
    điệu dạng
    phá huỷ
    bệnh tật
    thứ nhất
    gần như
    để dành
    đem đến
    tới
    trẻ trung
    rời khỏi
    thế mạnh
    khảo sát
    đồ vật
    đơn thuần
    ngừng
    sử dụng
    dùng
    êm ả
    kém chất lượng
    gắn bó
    mới đây
    gan lì
    thân thiện
    sát nhau
    gần
    gặp gỡ
    gấp gáp
    giả dụ
    giảng nghĩa
    tránh
    giảm
    hài hòa
    tận tình
    hiện đại
    hoàn hảo
    khá
    kém cạnh
    xoàng xĩnh
    kết cục
    kết quả
    mở màn
    luận điểm
    bao hàm
    trùng hợp
    khi
    làm cho
    không
    khuyến mãi
    kiện
    lăng băng
    xóm
    chỉ dẫn
    rét
    chếnh choáng
    lào xào
    tiện lợi
    thu hút
    to
    ma mãnh
    mô tả
    mua
    nắm
    tài năng
    nặng nề
    nấu nướng

    ngạc nhiên
    nhãn hàng
    nhanh
    bừa bãi
    rầm rộ
    nổi bật
    nổi tiếng
    oai nghiêm
    ổn thỏa
    pha trộn
    tốt
    phẳng lì
    trở thành
    nguyên tắc
    yêu thích
    quảng cáo
    qua chuyện
    quan tâm
    rách rưới
    rậm rì
    rẻ mạt
    rõ rệt
    mênh mông
    tinh khiết
    thông minh
    sáng
    sang
    thâm thúy
    kiêng dè
    tái mét
    tai họa
    tài xế
    tàn phế
    tang vật
    tàu bay
    thoải mái
    bác sĩ
    thừa mứa
    nối tiếp
    Tuy thế
    u ám
    đầm đìa
    va chạm
    van xin
    vắng ngắt
    lặt vặt
    xa vời
    hoang phí
    xâm lăng
    xanh rì
    xấu xa
    van nài
    hoàn thành
    xu thế
    dự định
    dựa dẫm
    quần áo
    y chang
    yên lặng
    yêu thương
    yếu ớt

    ReplyDelete
  16. Hi there, I discovered your site by way of Google while searching for a comparable topic, your weeb site
    got hre up, it seems good. I have bookmarked it in my google
    bookmarks.
    Helklo there,just turned into alert to youyr blog thru Google,
    and locatedd that it's really informative.I'm gonna watch out for brussels.
    I will be grateful in case you proceed this in future.
    A lott of other folks might be benefited from your writing.
    Cheers!

    ReplyDelete
  17. I like the helpful info you provide in your articles.
    I'll bookmark your blog and check again here regularly. I'm quite certain I'll
    learn plenty of new stuff right here! Good
    luck for the next!

    ReplyDelete
  18. What a information of un-ambiguity and preserveness
    of valuable knowledge on thee topic of unpredicted feelings.

    ReplyDelete
  19. You should be a part of a contest for one of the finest websites on the web.
    I will highly recommend this site!

    ReplyDelete
  20. It's actually a cool and helpful piece of information. I am
    happy that you just shared this useful information with us.
    Please keep us informed like this. Thank you for sharing.

    ReplyDelete
  21. I have read several good stuff here. Certainly price bookmarking for revisiting.
    I surprise how so much effort you put to make the sort of excellent informative
    website.

    ReplyDelete
  22. I do trust all of the ideas you have offered in your post.
    They are very convincing and will definitely work.
    Still, the posts are too short for starters. May you please lengthen them a little from subsequent time?
    Thanks for the post.

    ReplyDelete
  23. Terrific work! That is the type of information that are meant
    to be shared across the net. Shame on the search engines
    for now not positioning this submit upper! Come on over and visit my site .
    Thanks =)

    ReplyDelete
  24. This article will help tthe internet people for building up neew weblog or even a
    blg from sstart to end.

    ReplyDelete
  25. This website was... how do I say it? Relevant!! Finally I have
    found something which helped me. Many thanks!

    ReplyDelete
  26. Hi, Neat post. There's a problem along with your website in web explorer, could test this?
    IE nonetheless is tthe marketplace chief and a good portion of people
    will pass over your fantastic writing because of this problem.

    ReplyDelete

Post a Comment

If you Satisfied , Please Leave a comment

Popular posts from this blog

List of Post Category Wise in wordpress