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?

Answers


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.


Need Your Help

Sharepoint 2013 MMS not returning termstores

c# sharepoint sharepoint-2013

I am naive to sharepoint. I have observed a behaviour which is quite weird.

WiX Installing Server Control to Toolbox

wix vsx

I've got a server control in a dll deployed as part of a wix msi installation. I have gotten the installer to make the control available in the toolbox's ADD ITEMS window, but the contol isn't add...