【发布时间】:2016-08-26 22:48:03
【问题描述】:
我不知道我的问题的正确术语是什么,但我想将客户 ID 放在 href 中,例如 href='index.php/site/get_all_services_ajax/{obj.customer[i ].customer_id}。
请参阅我的代码中的第 5 行。我该怎么做?
<div id='mycoord'></div>
<script>
$(document).ready(function() {
$.get('<?php echo base_url();?>index.php/site/get_all_customer_ajax', function (data) {
var obj = JSON.parse(data)
for (var i=0; i < obj.customer.length; i++)
{
$('#mycoord').append("<a href='<?php echo base_url();?>index.php/site/get_customer_info/{obj.customer[i].customer_id}' <h2>" + obj.customer[i].first_name + "</href></h2><br>");
}
})
});
</script>
【问题讨论】:
-
不要用 PHP 构建 JS,更不要用 PHP 构建 JS 来构建 HTML。使东西工作所需的转义量变得更加复杂。
-
为什么?我只是做一个简单的查看..
标签: javascript jquery json codeigniter-3