1
<script type="text/javascript">

 var id=<?php print''.entry1->id.''?>;
 var dataString = 'id='+ id;

 $.ajax({
   type: "POST",
   url: "ajax_unfollow.php",
   data: dataString,
   cache: false,
 });         

</script>

there have a error in this line

var id=<?php print''.entry1->id.''?>;

how can i write php code in var id?

this javascript run in a foreach loop.

4 Answers 4

3

write like this :

var id= '<?php echo entry1->id;?>';
Sign up to request clarification or add additional context in comments.

Comments

2

You can try this

var id = '<?=$entry1->id?>';

Comments

0

You should add a single quotes around your PHP expression.

So, the corrected code should be:

var id='<?php print''.entry1->id.''?>';

Also, another thing:

You should avoid short_open_tag.

So, please use <?php echo $variable;?> instead of <?=$variable;?>.

Because, most of the PHP running servers should have short_open_tags directive off.

So, your PHP code, in this case will be considered as a plain text and will be shown to user.

Without it, whatever generated by the PHP should be considered as a JavaScript variable.

Which should cause an error.

Comments

0

since value of print should be string so you can try this code.

var id="<?php print''.entry1->id.''?>";

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.