Jquery 自动完成帮助

发布于 2024-11-07 23:21:33 字数 1366 浏览 0 评论 0原文

好的,这里需要一些帮助。我有一个自动完成设置,可以从数据库中提取所有正确的信息。我开始使用对话框,它工作过一次,但不久后就停止了。有谁明白为什么我的自动完成功能无法正确填写此文件?

 function clientJob() {
        showDialog('<p>Enter your Client Job Code</p><input type="text" size="15" name="projectnumber" id="projectnumber" value="" /><br /><input type="button" onclick="isaclientjob()" value="Enter" />');
    } 

    $( document ).ready(    
        function()
        {showDialog('<p>Is this a client job?</p><br /><input type="button" onclick="clientJob()" value="Yes" /> <input type="button" onclick="nonclientJob()" value="No" />');
            } // function
            ) // submit
            $( '[name="projectnumber"]' ).autocomplete({
                source: "job_validate.php",
                minLength: 3
            });
        }
    );

job_validate.php

$output = array();
$job = new job;
$jobs = $job->get_from_db( "`code` LIKE '" . $_GET['term'] . "%' AND `active` = '1'",'code',10 );

foreach ( $jobs as $key => $current)
    {
        $output[$key]['value'] = $current->code . " " . $current->name;
        $output[$key]['id'] = $current->id;
    }

print_r($output);
echo json_encode($output);

查看旧版本并恢复到它,如果我在那里有自动完成功能,它似乎在第一个对话框中工作正常,但一旦我进入下一个对话框,它就会工作正常搞砸了。

Ok need some help here. I have an autocomplete setup to pull from a DB with all of the right info. I started working with dialog boxes and it worked once but stopped a little while after. Does anyone see why my autocomplete wouldn't fill in correctly in this file?

 function clientJob() {
        showDialog('<p>Enter your Client Job Code</p><input type="text" size="15" name="projectnumber" id="projectnumber" value="" /><br /><input type="button" onclick="isaclientjob()" value="Enter" />');
    } 

    $( document ).ready(    
        function()
        {showDialog('<p>Is this a client job?</p><br /><input type="button" onclick="clientJob()" value="Yes" /> <input type="button" onclick="nonclientJob()" value="No" />');
            } // function
            ) // submit
            $( '[name="projectnumber"]' ).autocomplete({
                source: "job_validate.php",
                minLength: 3
            });
        }
    );

job_validate.php

$output = array();
$job = new job;
$jobs = $job->get_from_db( "`code` LIKE '" . $_GET['term'] . "%' AND `active` = '1'",'code',10 );

foreach ( $jobs as $key => $current)
    {
        $output[$key]['value'] = $current->code . " " . $current->name;
        $output[$key]['id'] = $current->id;
    }

print_r($output);
echo json_encode($output);

Looked at the old version and reverted back to it and it seems to work fine in the first dialog box if I have the autocomplete in there but as soon as I go to the next dialog box it gets screwed up.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

Saygoodbye 2024-11-14 23:21:33

我注意到您输出 $output 两次:

print_r($output);
echo json_encode($output);

尝试注释掉 print_r($output); 因为它会弄乱传输回 jQuery 的 JSON(因为它是无效的 JSON)。

I noticed that you're outputting $output twice:

print_r($output);
echo json_encode($output);

Try commenting out the print_r($output); because it will mess up the JSON being transferred back to jQuery (since it's not valid JSON).

明月松间行 2024-11-14 23:21:33

尝试:

 $( '[name="projectnumber"]' ).live('focus',function(){
            $(这个).自动完成({
               来源:“job_validate.php”,
               最小长度:3
            });
        });

也删除线
} //函数

) //提交

Try:

       $( '[name="projectnumber"]' ).live('focus',function(){
            $(this).autocomplete({
               source: "job_validate.php",
               minLength: 3
            });
        });

Also remove the lines
} //function
and
) //submit

哽咽笑 2024-11-14 23:21:33

我最终只使用了一个对话框并转到不同的功能,而不是多个对话框。感谢大家的帮助。

I ended up using just one dialog box and going to different functions instead of multiple boxes. Thanks for everyones help.

不喜欢何必死缠烂打 2024-11-14 23:21:33

如果不查看 job_validate.php 中的内容,就很难回答。我首先会回到工作的地方。添加每一行代码以查看是什么破坏了它,然后检查原因。

Without seeing what is in job_validate.php it'll be rather difficult to answer. I would start by working back to where it was working. Adding in each line of code to see what's breaking it and then examining why.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文