我正在生成这段代码
$.ajax({
url: '/orders/modify/action/',
type: "POST",
dataType: 'json',
data: 'id='+10+
'&commento='+$('#shop_order_status_history_comments').val()+
'&id_status='+$('#shop_order_status_history_orders_status_id').val()+
'¬ify_client='+$('#shop_order_status_history_notify_client').val()+
'&local_part_email='+j.garpe+ // the error goes here
'&domain_email='+domain.com,
success:function(data){
但是我收到了这个错误:
"Uncaught referenceError: j is not defined".
代码是这样的:
...
'&local_part_email='+<?php echo $local_part_email?>+
...
有什么帮助吗?
问候
贾维
最佳答案
它需要用引号括起来,像这样:
'&local_part_email=<?php echo $local_part_email?>'+
...但是接下来您将遇到与 domain
相同的问题,最好将其放在引号中 让 jQuery 通过传递一个对象来创建字符串像这样数据
:
data: {id: 10,
commento: $('#shop_order_status_history_comments').val(),
id_status: $('#shop_order_status_history_orders_status_id').val(),
notify_client: $('#shop_order_status_history_notify_client').val(),
local_part_email: '<?php echo $local_part_email?>',
domain_email: '<?php echo $whatever_domain_variable_here?>' }
关于php - JS/jQuery/PHP : trying to generate an URL using PHP variables,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4489389/