Use jquery variable in php
Problem in passing Jquery variable to php . Show When i pass variable id to
How to solve this problem ???? This
This
I want id variable to pass on to
Mr. Alien 149k33 gold badges288 silver badges272 bronze badges asked Apr 5, 2013 at 11:39
3 Try this one:
Then B.php
answered Apr 5, 2013 at 11:48
Try changing the input type to button instead of submit answered Apr 5, 2013 at 11:44
The problem is that your form is submited ,
Add
Lodder 19.7k10 gold badges58 silver badges96 bronze badges answered Apr 5, 2013 at 11:48
Shijin TRShijin TR 7,26010 gold badges47 silver badges115 bronze badges 2 Use a hidden field to set the value you want to send across. Since you are using submit, your entire form is submitted. The hidden field is also sent and this can be accessed directly using the name of the hidden field. answered Apr 5, 2013 at 11:49
AashrayAashray 2,71515 silver badges22 bronze badges 2
Try code above. First: JS does not allow to do something like this: Another problem: you must prevent default submit of a form. EDIT: This is to post a value with regular submit, so browser is redirected to B.php
answered Apr 5, 2013 at 11:44
Viktor S.Viktor S. 12.6k1 gold badge26 silver badges51 bronze badges 2 Try this code,
Here you can pass value of 'id' to B.php,And will be access as $_POST['id1'] answered Apr 5, 2013 at 12:08
Shijin TRShijin TR 7,26010 gold badges47 silver badges115 bronze badges Try this:
Since you are using ajax feature so you have to stop the form submit feature. You have a trailing comma here Note:You posted this error:
Don't run the page in filesystem Instead try using
answered Apr 5, 2013 at 11:44
JaiJai 73.4k12 gold badges73 silver badges99 bronze badges 4 Or you could use submit() this way
And form
EDIT: Oh and yeah for B.php isset check or error_reporting(0);
answered Apr 5, 2013 at 12:28
ZhamaZhama 12 bronze badges Not the answer you're looking for? Browse other questions tagged php javascript jquery or ask your own question.Can we use jQuery variable in PHP?You cannot use javascript variable in php. However you can use php variable within javascript. Javascript is client side and php is server side, if you want to use then send with ajax because its like sending from client to server.
How do you pass a jQuery variable to PHP and then display it?By adding e.preventDefault(); Error has been resolved but after submitting it should go to B.php and echo value of variable a. – Abhishek. Apr 5, 2013 at 11:58.. Then,You need to remove ajax,$.post is used for ajax submit.that will not redirect to B.php.That create xmlhttp request. – Shijin TR. Apr 5, 2013 at 12:11.. Can I use Javascript variable in PHP?The way to pass a JavaScript variable to PHP is through a request. This type of URL is only visible if we use the GET action, the POST action hides the information in the URL. Server Side(PHP): On the server side PHP page, we request for the data submitted by the form and display the result. $result = $_GET [ 'data' ];
How can get jQuery variable value in PHP without ajax?Create an hidden input tag in HTML , then set it's value as a JSON string with jquery. Next whenever you need that data , simply call the PHP function which returns value of input tag .. var jsdata = {. data: "Test". var jsondata = $. toJson(jsdata);. $("#transferInput"). val(jsondata);. |