0

在我的 php 文件中,javascript/html 代码是使用 echo 编写的。我想访问将要放置在 javascript 中“place1”div 中的图像并将其传递给 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'];
4

1 回答 1

0

在您的 jquery 中,您必须在发送时使用键/值对data

key=value

考虑到这一点,对于您data要发送的内容,您正在使用变量frame,但frame没有键/值对。它应该是:

var frame = "frame="+$("#place1").children("img").attr("src");

这将允许您在 PHP 中捕获变量:

$frame = $_POST['frame']

于 2013-03-26T21:30:46.637 回答