使用JavaScript来改变量程输入(反之亦然),然后AJAX的更新的输入? [英] Using javascript to change span to input (viceversa) and then AJAX the updated input?

查看:104
本文介绍了使用JavaScript来改变量程输入(反之亦然),然后AJAX的更新的输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我有这个code作为我跨度:

I currently have this code as my span:

 <span class="subheading">
 <span id="loadNum"><?php echo $status ?></span>
 &nbsp;&nbsp;
 <i class="fa fa-question-circle" rel="tooltip" title="Click on your status to change it." id="blah"></i>
 </span>

现在我用这code作为JavaScript的:

Now I am using this code as for the javascript:

    <script>
       var switchToInput = function () {
        var $input = $("<input>", {
            val: $(this).text(),
            type: "text",
            style: "color: #000"
        });
        $input.attr("ID", "loadNum");
        $(this).replaceWith($input);
        $input.on("blur", switchToSpan);
        $input.select();
    };
    var switchToSpan = function () {
        var $span = $("<span>", {
            text: $(this).val()
        });
        $span.attr("ID", "loadNum");
        $(this).replaceWith($span);
        $.ajax({
            type:"POST",
            url:"includes/ajaxprocess.php",
            data:{status: status},
            success:function(data){
               $("#info").html(data);
            }

        });
        $span.on("click", switchToInput);
    }
    $("#loadNum").on("click", switchToInput);
</script>

最后但并非最不重要 ajaxprocess.php

And last but not least ajaxprocess.php

<?php
mysql_connect("localhost","root","");
mysql_select_db("blogger");

$status=$_POST["status"];

$query=mysql_query("UPDATE blog_members (status) values('$status') ");

if($query){
    echo "Your status has been updated";
}
else{
    echo "Error in updating your status";
}
?>

但是,当我更新我的状态,让输入变得跨度,数据库的字段不更新。我怎么能做出这样的工作。

But when I update my status, and let the input become a span, the field of the DB doesn't update. How could I make this work.

BTW:$状态定义。不要担心。

BTW: $status is defined. dont worry about that.

推荐答案

更​​新语法是错误的。

You UPDATE syntax is wrong.

UPDATE blog_members 
SET status=-- status information 
WHERE user_id=--identifying who the status belongs to

关于更新

MySQL手册录入

这篇关于使用JavaScript来改变量程输入(反之亦然),然后AJAX的更新的输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆