简体   繁体   English

var属性用php回显,而不是从表单提交

[英]var attribute echoed with php and not submitted from form

Using this 用这个

`$(function(){$(".signaler").click(function(){var element=$(this);var I = element.attr("id");var page = $('#page').attr('value');var info = "id="+I+"& page="+ page;$("#signaler"+I).hide();$("#load"+I).html('<img class="think" src="load.gif" >');$.ajax({type:"POST",url:"signaler.php",data:info,success:function(){$("#load"+I).empty();$("#ok"+I).fadeIn(200).show();}});return false;});});`

but have a form with hidden inputs only so i can echo current user info into it, was wondering if I could put it straight into jquery? 但是只有一个隐藏输入的表单,所以我可以将当​​前的用户信息回显到它,想知道我是否可以直接进入jquery? Working fine though. 虽然工作正常。

With a form you would use the following 使用表格,您将使用以下内容

var page=$('#page').attr('value');

I would like to set the id with php echoing user name/id.. 我想用php echoing用户名/ id设置id。

Something like var id=$('<?php echo $user/$id... ?>'); var id=$('<?php echo $user/$id... ?>');

If someone could point out the right jquery syntax, would be very greatful! 如果有人能够指出正确的jquery语法,那将是非常棒的!

var id = $(<?= $_POST["whatever_it_was"] ?>)

pretty much what you used as an example... 几乎就是你用的例子......

<?php echo $user . '/' . $id ?>

As long as the file in question is being parsed as php by the server that is... 只要有问题的文件被服务器解析为php即...

Firstly you should get the value of a form input using the val() method: 首先,您应该使用val()方法获取表单输入的值:

$('input#id').val();

Then on the PHP side if you POST to the page using AJAX then do: 然后在PHP端如果你使用AJAX POST到页面然后执行:

'var id=$('<?php echo $_POST['user'] . '/' . $_POST['id'] ?>')';

What you have is essentially a string you wish to use for somewhere in you jQuery. 本质上,您想要在jQuery中的某个地方使用的字符串。 Well in that case what you have is essentially correct. 那么在这种情况下,您所拥有的基本上是正确的。 If in your PHP file you do (notice the quotation marks: 如果你在你的PHP文件中(注意引号:

var id = "<?php echo $yourId ?>";

You can then use that variable (which holds your PHP string) normally. 然后,您可以正常使用该变量(包含您的PHP字符串)。 The following would for example select the element with the id in the variable id : 例如,以下示例将在变量id选择ID为的元素:

$('#' + id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM