php - JS/jQuery/PHP : trying to generate an URL using PHP variables

标签 php javascript jquery

我正在生成这段代码

$.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()+
              '&notify_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/

相关文章:

java - PHP中的前置增量和后置增量

javascript - 为什么我的函数没有定义?

javascript - 通过window.print()方法打印输入框运行时值

javascript - 专用 jQuery AJAX 函数中的错误回调

php - jquery-ajax : pass values from a textfield to a php variable (same a file)

php - 如何在 windows 上使用 composer 运行 phpunit 测试(cmd)

php - php中fileatime和filectime的区别

PHP 位掩码在应该为假时说真

javascript - 这个语法是什么: []._

javascript - 使用显示方法