开发者

pass jQuery value to php

for example, i have got this value in my php file:

<script type="text/javascript">
function altcat(id) {
        $ogzu = id;
    }
</script>

i want to use $ogzu value in php. is it possible? can i pass a value to php from jquery? i need to learn this answer.

can anyone help me please? thanks 开发者_开发技巧and regards

edit:

thanks for your kindly replies. i wanted to use $ogzu value in php like that:

<?php
echo "<a href='".$ogzu."'>test link</a>";
?>

well, i know its wrong. its already not working. i want to learn if we are able to use jquery values in php? thanks again friends. regards


You can use ajax something like this:

$.ajax({
  url:'yourfile.php',
  type:'GET',
  data: {id:yourVariable},
  success:function(res){
    // code
  }
});


You can POST ($.post() for shorthand) or GET ($.get() for shorthand) to PHP, whichever is needed, for example:

$.post("myPage.php", { id: $ogzu }, function(data) {
  alert("Response from server: " + data);
});

If you want it to be included in a <form> you're already submitting, just set the hidden input to that value, for example:

<input type="hidden" id="ogzu" name="ogzu" />

And matching script:

function altcat(id) {
   $("#ogzu").val(id);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜