Saturday 15 August 2015

access variable defined in Javascript (jQuery) in php -


The javascript / html code in my php file is written using echo. I would like to use the image which is being kept in javascript in "place1" div and pass it on php

Here is my code:

  // Create a placeholder for an image - the user is dragging and dragging an image, here "echo id = 'place1' class = 'location'> gt; & lt; / div & gt;"; Echo; & Lt; Button ID = "Apply" name = "save" type = "submit" & gt; Apply changes & lt; / Button & gt; '; Echo '& lt; Script src = "http://code.jquery.com/jquery-1.9.1.js" & gt; & Lt; / Script & gt; '; // javascipt code to find the source of the image '& lt; Script & gt; $ (Document) .ready (function () {$ ("# apply") Click (function () {var frame = $ ("# place1"). Children ("img"). Attr ("src"); $ .ajax ({url: "thumbnails.php", type: "POST", data: frame});});}); & Lt; / Script & gt; '; // login frame variables (image source) in php ??? Not sure how to do this part. $ Frame = $ _ post ['frame'];      

in your jquery when sending you the data A key / value pair should be used :

key = value

With this in mind, enter your data < For the / code>, which you are sending, you are using your variable frame , but there is no key / value added in frame should be:

  var frame = "frame =" + $ ("# location1"). Children ("img"). Attr ("src");   

It will now allow you to capture the variable in PHP:

$ frame = $ _POST ['frame']

No comments:

Post a Comment