Jquery 自动完成帮助
好的,这里需要一些帮助。我有一个自动完成设置,可以从数据库中提取所有正确的信息。我开始使用对话框,它工作过一次,但不久后就停止了。有谁明白为什么我的自动完成功能无法正确填写此文件?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我注意到您输出
$output
两次:尝试注释掉
print_r($output);
因为它会弄乱传输回 jQuery 的 JSON(因为它是无效的 JSON)。I noticed that you're outputting
$output
twice: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).尝试:
也删除线
} //函数
和
) //提交
Try:
Also remove the lines
} //function
and
) //submit
我最终只使用了一个对话框并转到不同的功能,而不是多个对话框。感谢大家的帮助。
I ended up using just one dialog box and going to different functions instead of multiple boxes. Thanks for everyones help.
如果不查看 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.