Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Can anyone tell me how can i get the value of a variable in jquery then control it at the level of server with php?

user-image
Question added by Joel Foba , Developper /Administrateur sustème , World Engineering Consulting Internationale (WEC)
Date Posted: 2013/12/04
Fadi Alkhateeb
by Fadi Alkhateeb , Senior Front End Developer , NexTwo

You will need to use Ajax in Jquery to pass the javascript variable to a php script and use it whatever you want.

 

Below is a declaration for  Ajax() in jQuery:

ajax()

 

 

 

Muhammad Majid Saleem
by Muhammad Majid Saleem , Senior PHP Developer / Project Manager , SwaamTech

You can do this using an Ajax call. Please find an example below:

 

<script type="text/javascript" language="javascript">

$(document).ready(function(){

 

// get your variable values upon some action or as per your desire. I am assuming you clicked a button to get some variable value.

$("#submit").click(function(){

var fullname = $("#fullname").val();

 

// Send an ajax call.

$.post("example.php", { fullname :fullname } , function( data ){       

    // Do something as per your logic.}, "json");

});

});

});

</script>

 

exmple.php<?php$fullname = $_POST['fullname'];

// Now you can use it on server side as you want.?>

Asif Ali M
by Asif Ali M , Project Lead , LiquidHub

There is a possibility of sending a javascript variable to php. You need to explain what exactly you are trying to do.

More Questions Like This