[英]Quoting issue while echoing a html part from php to jquery
In my php file I am echoing back an html response to my jQuery function. 在我的php文件中,我回显了对jQuery函数的html响应。 Due some wrong quoting that I am applying data is no being passed through onclick event
由于我正在应用数据的一些错误报价无法通过onclick事件传递
echo " <div class='img-x' id='img-x-".$newdata['id']."' ><span onclick='test('".$newdata['id']."','".$newdata['image_path']."');' class='icon-remove'></span></div> <img src='http://localhost/corridor/uploads/".$actual_image_name."' class='img_prvw' id='img-x-".$newdata['id']."' />";
in html it shows like this 在HTML中,它显示像这样
<span onclick="test(" 164','13906347455190.jpg');' class="icon-remove"></span>
Where am I doing it wrong? 我在哪里做错了?
Try escaping the quotes
properly. 尝试正确转义
quotes
。
echo "<div class='img-x' id='img-x-".$newdata['id']."'><span onclick=\"test('".$newdata['id']."','".$newdata['image_path']."');\" class='icon-remove'></span></div> <img src='http://localhost/corridor/uploads/".$actual_image_name."' class='img_prvw' id='img-x-".$newdata['id']."' />";
^
I am assuming you are ajaxing this in: 我假设您正在用以下方式来避免这种情况:
echo <<< _html
<div class="img-x" id="img-x-$newdata['id']">
<span data-id="$newdata['id']" data-imagepath="$newdata['image_path']"
class="icon-remove"></span>
</div>
<img src="http://localhost/corridor/uploads/$actual_image_name"
class="img_prvw" id="img-x-$newdata['id']" />
_html;
and in the succes: 并成功:
success: function() {
$("#someContainer").html(data);
$("#someContainer .icon-remove").on("click",function() {
test($(this).data("id"),$(this).data("imagepath"));
});
}
If no ajax then 如果没有ajax的话
echo <<< _html
<div class="img-x" id="img-x-$newdata['id']">
<span onclick="test('$newdata['id']','$newdata['image_path'].')"
class="icon-remove"></span>
</div>
<img src="http://localhost/corridor/uploads/$actual_image_name"
class="img_prvw" id="img-x-$newdata['id']" />
_html;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.