0

I have try to pass a java script variable to PHP method from this way. But I have done wrong way. How do implement it in a correct way.

<script>
       function showMe(id){
           var name = <?php findDriverName(id,$drivers); ?>             
       }
</script>

The variable id is the Java Script Variable I need to pass this to PHP method findDriverName

3
  • Why you cant use ajax? otherwise you need to submit a form and make a post request. Commented Jun 30, 2015 at 2:49
  • 1
    possible duplicate of How to pass data from Javascript to PHP and vice versa? Commented Jun 30, 2015 at 2:52
  • can we call in line php function to ajax call. mean the ajax call and php function are in a same file Commented Jun 30, 2015 at 3:02

1 Answer 1

4

To get data to your PHP script, it has to be included in an HTTP request somehow. You can store it in a cookie, or do an AJAX request, or do a form POST/GET, but you have to have an HTTP request.

AJAX is your friend here.

Sign up to request clarification or add additional context in comments.

3 Comments

So there is no way to do it without ajax am i right?
Could you please help me to do this task in ajax
That's probably the right way to do it in your case, based on the limited context I have. As I commented, you need to have an HTTP request involved, so your options are to post a form or do an AJAX call (which basically just posts a form anyway.)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.