[jQuery] form fields not being updated from json response via .ajax
Hi all,
I'm working with some json and .ajax to update fields on a form when
an option is changed on a select box. Everything works fine. I can
see my json data is getting returned correctly in firebug. What I
cant get working is updating the input fields with the date returned.
I have the following code:
$(document).ready(function() {
var selectid = "#ID-NUM";
$(selectid).change(
function() {
$.ajax({
type: "POST",
url: "json.html",
cache: false,
data: "sessid=`trim(string(v-session-id))`&" + this.name
+ "=" + this.value,
dataType: "json",
success: function(data){
$("#COMPANY").val(data.companyname);
$("#ROUTING_NUMBER").val(data.routing);
}
});
}
);
});
Example returned json data:
[{
"rowid": "0x0000000001b04e1f",
"custnumber": "2456",
"custaddr1": "",
"custaddr2": "",
"city": "",
"prov": "",
"pcode": "",
"entrysource": "WEB",
"routing": "312312312",
"companyname": "Joes Video",
}]
How do I set the value of the input fields COMPANY and ROUTING_NUMBER
to the returned json values? I have the id set on both fields
correctly. I can see the data being returned in firebug?
Am I missing something?