tirenweb
tirenweb

Reputation: 31709

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

i'm generating this code

$.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){

But I'm getting this error:

"Uncaught referenceError: j is not defined".

The code is this:

      ...  
      '&local_part_email='+<?php echo $local_part_email?>+
      ...

Any help?

Regards

Javi

Upvotes: 1

Views: 75

Answers (1)

Nick Craver
Nick Craver

Reputation: 630409

It needs to be in quotes, like this:

'&local_part_email=<?php echo $local_part_email?>'+

...but you'll have the same problem with domain next, it's best to put it in quotes and let jQuery create the string, by passing an object to data like this:

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?>' }

Upvotes: 2

Related Questions