twitter-bootstrap 使用 X-editable for Bootstrap 将值发送到 post.php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14314991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 16:06:01  来源:igfitidea点击:

Use X-editable for Bootstrap to send values to post.php

phpjquerytwitter-bootstrap

提问by Cognis

I use Twitter Bootstrap and decided to use X-editable with it. I put in all the necessary files and it works fine except that I want to pass values to post.phpwhere I want PHP to process $_POST["value"].

我使用 Twitter Bootstrap 并决定使用 X-editable。我放入了所有必要的文件,它工作正常,只是我想将值传递到post.php我希望 PHP 处理的地方$_POST["value"]

Markup of the editable element is

可编辑元素的标记是

<a href="#" id="example">Example</a>

I call it like this

我这样称呼

$(function() {
  $.fn.editable.defaults.mode = 'inline';

  $('#example').editable({
  type: 'text',
  pk: 1,
  url: 'post.php',
  title: 'Enter example'
   });
});

I used jEditableas an inline editor in which I passed on values to a php file with no problems and I would like to do so with X-editable but I can't seem to do it.

我使用jEditable作为内联编辑器,在其中我将值传递给 php 文件没有任何问题,我想使用 X-editable 这样做,但我似乎无法做到。

How do I pass the values to post.phpso I can use php to manipulate the data?

如何将值传递给post.php以便我可以使用 php 来操作数据?

回答by reid

<a href="#" id="example">Example</a>

<a href="#" id="example">Example</a>

you must add data-name=""

您必须添加数据名称=""

<a href="#" id="example" data-name="db-col-name">Example</a>

<a href="#" id="example" data-name="db-col-name">Example</a>

so when you access it in post.php, you can do like this:

所以当你在 post.php 中访问它时,你可以这样做:

$name = $_POST['name']// $_POST['name'] catches the data-name value

$name = $_POST['name']// $_POST['name'] 捕获数据名值

$pk= $_POST['pk']// the pk(primary key) that you assigned

$pk= $_POST['pk']// 你分配的 pk(primary key)

$value= $_POST['value']// the new value after you use the inline edit

$value= $_POST['value']// 使用内联编辑后的新值

after that you could do something like this

之后你可以做这样的事情

if(!empty($value)) {

if(!empty($value)) {

$result = mysql_query('update users set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where user_id = "'.mysql_escape_string($pk).'"');

$result = mysql_query('update users set '.mysql_escape_string($name).'="'.mysql_escape_string($value).'" where user_id = "'.mysql_escape_string($pk).'"');

} else {
    header('HTTP 400 Bad Request', true, 400);
    echo "This field is required!";
} `

credits to the makers of x-editable its from their php sample more info here

从他们的 php 示例中获得x-editable 的制造商的功劳, 更多信息在这里

回答by Sudhanshu sharma

you should do something like this

你应该做这样的事情

<a href="#" id="roll_no" data-type="text" data-pk="<?php echo $row['id'] ?>" data-url="ajax.php" ><?php echo $row['roll_no']; ?></a>

Reference :- jQuery x editable tutorial

参考:- jQuery x 可编辑教程