-1

如果我键入的输入文本不匹配,我该如何更改值 id?这是代码:

<script src="jquery-1.4.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.autocomplete.css" />
<script>
$(document).ready(function()
{
    $('[id^="participant"]').keyup(function() 
    {
        var txt = $(this).val();
        $.ajax({
            type: "POST",
            url: "blue.php",
            data: "nameparticipant=" + txt,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function(data)
            {
                $(this).next().val(data.d); 
            },
            failure: failerEvent
        });
    });
});
</script>

这是php代码:

<?php
include"connection.php";
$nameparticipant=$_POST["nameparticipant"]);
$res = mysql_query("select * from tabel where upper(name) like '$nameparticipant%'");
$t=mysql_fetch_array($res);
echo "$t[id]";
?>

这是html正文:

<input type="text" id="participant1"  name="name[1][]" value="Andi"/>
<input type="text" id="idparticipant1" name="idparticipant[1][]" value="1001"/>

<input type="text" id="participant2"  name="name[2][]" value="Smith"/>
<input type="text" id="idparticipant2" name="idparticipant[2][]" value="1005" />

我能做些什么 ?请帮我 :(

4

2 回答 2

0

我不知道您要做什么,但是我发现您的代码存在很多问题。

首先,contentType: "application/json; charset=utf-8",这是发送到服务器的数据的内容类型。您没有将 JSON 发送到服务器,因此不需要此行,请将其删除。

第二,failure: failerEvent。选项是error,不是failure。应该是error: failerEvent

第三,echo "$t[id]";。在您的 AJAX 调用中,您说dataType: 'json',这意味着 jQuery 期望服务器输出 JSON。我只能假设id您的数据库表中的字段实际上不是 JSON 字符串。你可能想要echo json_encode($t).

于 2012-02-23T05:40:37.323 回答
0

请详细说明您到底想做什么,您的错误是什么?还有一个问题,为什么你在代码中使用两个 jquery?第一个 jquery-1.4.js 和第二个 jquery-1.3.2.min.js。

于 2012-02-23T05:42:12.923 回答