1

I'm currently using an ajax post to retrieve data from another page. For reusing the returned value in future, I want to assign it to a php variable. Is it possible?

success: function(data) {
 $('#display').html(data);
}
2
  • Are you really talking about php variable or js variable? Commented Dec 17, 2015 at 5:54
  • php variable. in the success function, the data is already there but I want to put it on a php variable Commented Dec 17, 2015 at 6:05

2 Answers 2

1

You can't. The php file completes its execution in the server first and the result is passed to the browser. The javascript (ie, ajax) part is then executed in your browser. Read the answer here for more info.

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

Comments

0

you can use like:

<script type="text/javascript">
var jvalue = 'this is javascript value';

<?php $abc = "<script>document.write(jvalue)</script>"?>   
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.