在我的php文件中,javascript/html代码是使用echo编写的。我想访问的图像,将被放置在"place1"div在javascript和传递给php。
下面是我的代码: // create a placeholder for an image- user is going to drag and drop an image here
echo "<div id= 'place1' class = 'place'></div>";
echo '<button id="apply" name="save" type="submit">Apply Changes</button>';
echo '<script src="http://code.jquery.com/jquery-1.9.1.js"></script>';
//javascipt code to find the source of that image
echo
'<script>
$(document).ready(function(){
$("#apply").click(function() {
var frame = $("#place1").children("img").attr("src");
$.ajax({
url: "thumbnails.php",
type: "POST",
data: frame
});
});
});
</script>';
// access frame variable (image source) in php ??? not sure how to do this part..
$frame = $_post['frame'];
在发送data
时必须使用键/值对:
key=value
考虑到这一点,对于您正在发送的data
,您正在使用变量frame
,但frame
没有键/值对。应该是:
var frame = "frame="+$("#place1").children("img").attr("src");
这将允许您在PHP中捕获变量:
$frame = $_POST['frame']