Jquery autocomplete help
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.
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).
Try:
$( '[name="projectnumber"]' ).live('focus',function(){ $(this).autocomplete({ source: "job_validate.php", minLength: 3 }); });
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.
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.
精彩评论