0

i want to comment a code block, but i have a line in my javascript block which has jquery and php both

like this

jq('.time_slot').each(function(index) {
    var a = jq(this).autocomplete({ 
        serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
        params: { suggessions_id:28767 }, //aditional parameters
        onSelect:function(value,data){ jq(this).trigger('change');  } 
    });
});

with out this line

      serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",

i can comment this block using

/*

*/

but now i can not use it , also i tried with single line comments , like this

//jq('.time_slot').each(function(index) {
    //var a = jq(this).autocomplete({ 
        //serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
       // params: { suggessions_id:28767 }, //aditional parameters
       // onSelect:function(value,data){ jq(this).trigger('change');  } 
   // });
   // });

but for this line

 serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",

it is not working .

so i ended up with a very odinary solution like this

 //serviceUrl:"
<? //echo $this->config->item('base_url'); ?>
//business/information/add/autocomplete",

what is the best way to comment my code block , thank you in advance .

4 Answers 4

2

On runtime, if your php configuration's short_open_tag is enabled, those script enclosed in <? ?> would have been parsed by php parser in the server before sending the html (that contains the said javascript with comment) to the browser.

So it should technically work if you use // to comment out that line, as the javascript parser won't be aware that the string was generated from php.

Make sure you have short_open_tag enabled or use <?php instead of short tags (<?).

Sign up to request clarification or add additional context in comments.

Comments

1

Ok, admittedly, this isn't pretty, but if you want to cancel out the commingled PHP and JavaScript in one fell swoop, you might consider wrapping the entire block in a PHP condition that always returns false, e.g:

<?php if (1 == 0) { ?>
jq('.time_slot').each(function(index) {
    var a = jq(this).autocomplete({ 
        serviceUrl:"<? echo $this->config->item('base_url'); ?>business/information/add/autocomplete",
        params: { suggessions_id:28767 }, //aditional parameters
        onSelect:function(value,data){ jq(this).trigger('change');  } 
    });
});
<?php } ?>

Ugly, I know, but undeniably quick and effective for big blocks of mixed code.

Comments

0

Afaik theres no better solution that you provided. PHP and JS comments are always separate, you can put JS comment into PHP's echo function.

PHP parser will always try to run code between blocks.

Imho best solution is to comment whole JS code using /* and */ and use single line comment to prevent PHP running php code block.

Comments

0

That is the best way already. Can't think of any better ways..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.