I am attempting to get a hidden form value which contains json, after the ajax request is loaded…
The odd thing is that jquery sees the hidden value that was just loaded via ajax… however it can’t get the value:
if ($("#json_nav").length) {
alert('element is there!');
var j = $("#json_nav").val();
alert(j); //is empty
}
my #json_nav is as follows:
<input type='hidden' id='json_nav' value='{"c_type":3,"c1":"1","c2":"617","c3":"769"}'/>
My code is working with none ajax requests…. and i have confirmed that the hidden value is being returned in the ajax request… but can not get the value…
My guess is that you have a different element on the page with the
id“json_nav”, and so you’re retrieving the value of that first one, rather than the new one.Here’s an example of what I mean:
Live copy
This is invalid (
idvalues must be unique), but it’s an easy mistake to make. Browsers will typically give you the first one when you look things up by ID, but of course it’s impossible to be certain as browsers are free to do what they want with invalid documents.