简体   繁体   中英

Jquery added by ajax request in php page doesn't work

i have a script jquery that upload an image and show it by a php script called in this way:

<script type="text/javascript" >
 $(document).ready(function() { 
 $('#photoimg').live('change', function(){ 
   $("#imageform").ajaxForm({target:'#logo'}).submit();
});
}); 
</script>

where photoimg is the input type file and image form the form. logo is the div where image will be.

Now when image is loaded in div whit php script in this way:

echo "<img src='".$actual_image_name."' id='imm' style=\"width:500;height:350;\" \>\n";

i have to add a jquery script to drag image inside the div to "center" it. if i use echo after the line before in this way:

echo '<script type="text/javascript">'; 
echo "$(function(){";
echo "var maskWidth  = $(\"#logo\").width();";
echo "var maskHeight = $(\"#logo\").height();";
echo "var imgPos = $(\"#imm\").offset();";
echo "var imgWidth = $(\"#imm\").width();";
echo "var imgHeight  = $(\"#imm\").height();";
echo "var x1 = (imgPos.left + maskWidth) - imgWidth;";
echo "var y1 = (imgPos.top + maskHeight) - imgHeight;";
echo "var x2 = imgPos.left;";
echo "var y2 = imgPos.top;";
echo "$(\"#imm\").css({top: 0, left: 0, cursor: 'move'});";
echo "$(\"#imm\").draggable({ containment: [x1,y1,x2,y2] });";
echo "});\n";
echo "</script>\n";

it doesn't work. can you help me pls?

You should never want to execute Javascript from an external source like this. Just put the code into the calling page/script and execute it after the Ajax content has been added.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM