Sunday, 15 September 2013

get value from javascript to php variable -



get value from javascript to php variable -

this dragable image facebook. when drag alter javascript value. question how value php when click button save changes?

this code javascript

$(document).ready(function(){ $('.wrap').imagedrag({ input: "#output", position: "middle", attribute: "html" }); });

and html

<span id="output"></span>

and want save database variable of php

look @ jquery.ajax(). can dynamicaly send variable value php.

example:

$.ajax({ type: "post", datatype: "json", url: "some.php", data: { name: "john", location: "boston" } }) .done(function( msg ) { alert( "data saved: " + msg ); });

in case :

your html

<span id="output"></span>

your javascript

// define click evenement button $('#output').click(function(){ // retrieve value want save var valuetosave = ...; // send value in php $.ajax({ type: "post", datatype: "json", url: "yourphppage.php", data: { "value": valuetosave } }) .done(function(msg) { alert("data saved!"); }); });

your php

if (($value = filter_input(input_post, "value", filter_unsafe_raw)) !== null) { // got value here }

javascript php get

No comments:

Post a Comment