Question: How can I send PHP variable sprod into ajax i need to send this id to check.php page 

```
<script>
function getState(val) {

    $.ajax({
    type: "POST",
    url: "check.php",
    data: {id: val, id2:$prod },
    dataType:'json',
    success: function(data){
        $("#style_code").children().remove();
        $("#style_image").children().remove();

         data.option.forEach(function (item) {
                $("#style_code").append('<option value="' + item.color_name + '">' + item.size + '</option>');
                $('#style_image').append('<img  src="images/'+item.image_name+'" data-imagezoom="true" class="img-responsive" alt="" />')               
            //$("#style_image").html(data);
            });
    }
    });
}
</script>

```

Answer: 
```
<script>
 var prod = <?php echo $prod ?>;
</script>

```

**Note** 

This should only works if your page is in `.php` extension
You can use `<?php ?>` tags in your script because you run it into ur .php file.

But you need to to open the `<?php ?>` tags to use php in the script tags.

Change

```
data: {id: val, id2:$prod },

```

To

```
data: {'id':val, 'id2':<?php echo $prod ?> },

```

Also(Better by my oppinion)

```
data: {'id': val, 'id2':<?= $prod ?> },

```

U can use `<?=?>` instead of `<?php ?>` to print something, so you don't need to write `echo` again.