I would like to use getJSON
to grab properties of an item that a user selects from a drop down menu.
However, when I place $.getJSON
in a function that is activated by the drop down selection it does not work.
//DOES NOT WORK :(
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
function json_tolerances() {
$.getJSON($SCRIPT_ROOT + '/_json_tolerances', { machine: $('#machine').val() }, function(data){
tolerances(data);
});
};
$('#machine').change(json_tolerances);
Strangely, when I place $.getJSON outside the function it works. Unfortunately, it is now not tied to my dropdown menu.
//WORKS :)
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
$.getJSON($SCRIPT_ROOT + '/_json_tolerances', { machine: $('#machine').val() }, function(data){
tolerances(data);
});
More strangely, when I hand code in the array that $.getJSON
is suppose to provide it works, so it is something to do with $.getJSON
.
//WORKS :)
var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};
function json_tolerances() {
//$.getJSON($SCRIPT_ROOT + '/_json_tolerances', {machine: $('#machine').val()}, function(data){
var data = {"result": [{"form_field": "polyethylene", "maximum": "-110", "minimum": "-80"}, {"form_field": "air", "maximum": "-993", "minimum": "-983"}, {"form_field": "acrylic", "maximum": "135", "minimum": "105"}, {"form_field": "water", "maximum": "4", "minimum": "-4"}]}
tolerances(data);
//});
};
$('#machine').change(json_tolerances);
I'm a newbie to javascript so any help would be greatly appreciated.