Reputation: 409
<script type="text/javascript">
$(document).ready(function() {
$(".edit").click(function(){
temp = $(this).attr('id').split("_");
$.get('/patients/getPlanofCareById', { "id": temp[1]},
function(data){
$('#patient-poc-frm').populate(data);
}, "json");
});
});
</script>
Firebug is throwing notices that the form elements do not exist but I see them using firebug. I am sure that they are there. You will notice that I am using jquery to post a variable and send back results using json.
Any
Upvotes: 0
Views: 423
Reputation: 75
Just for people that probably still come here after years and are searching for the same error (like me today :) ). Notice kbrin80's comment where he says that the console output states "No such element as [][id]" - this is the hint - at least it was for me. e.g. how my code looked:
<?php
$result = $database->select('table', ['colums'], ['id' => $value]);
$json = json_encode($result);
echo $json;
//echoes like: [{id=>value}]
//--> notice the outer pair of brackets, that's an array, you want to get rid of them!
?>
according script
<script type="text/javascript">
jQuery(document).ready(function(){
$('.populate').populate(<?php echo $json; ?>, {debug: 1});
});
</script>
This looks great in the first spot, but what happened is that I've forgotten that my DB-Framework returns an array containing results in an array of cause - even thogh there is only one row returned - still it is neccessary to choose this row by getting $redsult[0]. well, this array was then turned into json (visible by the [ ] around the {} and given into the populate jquery - which as we know doesn't work because in the first spot populate expects {id=>value} rather than [{id=>value}] (arrays within the {} are then used for multiselect values though) So what you want to do is figure out where in the array of your Database result the values you want are and just pass that into the json encoder and after that into populate. Like this:
$result = $database->select('table', ['colums'], ['id' => $value]);
$json = json_encode($result[0]);
echo $json;
//echos like: {id=>value} , you want that to pass through populate correctly
Upvotes: 1
Reputation: 35107
Even if the form elements don't exist you shouldn't be getting an error. jQuery doesn't work like that which means the errors you're seeing are either coming from another piece of javascript code or you've forgotten to include the jQuery library.
EDIT
Ah, you're using the form handler I see. I've never used it but I do notice something: Before you sent off the ajax request you're splitting the id attribute based on the underscore right? And the ID property you're sending in the JSON is the suffix. Is the resulting JSON appending the prefix back on when it returns? Otherwise if the ID was initially something like "textbox_name" you're going to be searching for an element with the ID "name" which won't exist.
Upvotes: 0