Here is what I got so far. Please read the comment in the code. It contains my questions.
var customer; //global variable function getCustomerOption(ddId){ $.getJSON("http://localhost:8080/WebApps/DDListJASON?dd="+ddId, function(opts) { $('>option', dd).remove(); // Remove all the previous option of the drop down if(opts){ customer = jQuery.parseJSON(opts); //Attempt to parse the JSON Object. } }); } function getFacilityOption(){ //How do I display the value of "customer" here. If I use alert(customer), I got null }
This is what should look like my json-object: {"3":"Stanley Furniture","2":"Shaw","1":"First Quality"}. I ultimately want that if I pass the key 3, I want to get Stanley Furnitureback, and if I go through Stanley Furniture, I get 3back. Because it 3is customerId, and Stanley Furnitureis the name customerName in my database.
{"3":"Stanley Furniture","2":"Shaw","1":"First Quality"}
3
Stanley Furniture
JSON ( URL-), jQuery $.getJSON(), JSON. jQuery.parseJSON(). . getFacilityOption() $.getJSON() function(opts) ( ).
$.getJSON()
jQuery.parseJSON()
getFacilityOption()
function(opts)
JSON
... " "
var json = {"3":"Stanley Furniture","2":"Shaw","1":"First Quality"}; alert(json['3']); // or var key = '3'; alert(json[key]);
JSON, . $.getJSON, .
$.getJSON
getJSON XHR. , , , getJSON - , jQuery , . , customer , .
getJSON
customer
parseJSON JavaScript:
parseJSON
var parsed = jQuery.parseJSON('{"foo":"bar"}'); alert(parsed.foo); // => alerts "bar"
.. , BalusC, -, jQuery , JS .
var customer; //global variable function getCustomerOption(ddId){ $.getJSON("http://localhost:8080/WebApps/DDListJASON?dd="+ddId, function(opts) { $('>option', dd).remove(); // Remove all the previous option of the drop down if(opts){ customer = opts; //Attempt to parse the JSON Object. } }); } function getFacilityOption(){ for(key in costumer) { alert(key + ':' + costumer[key]); } }
Source: https://habr.com/ru/post/1735285/More articles:Maintaining keyboard focus on a single control, but ListBox can still be used - wpfИспользуйте код VBA, чтобы нажать на кнопку на веб-странице. - htmlusing e as System.EventArgs in CheckChanged event CheckBox - .netМногократное наследование типа в Аде - polymorphismПрекращение мошенничества путем поиска шаблонов в данных - securityExiting the StarTeam Command Line - regexCan you query MongoDB for any properties with a given value? - mongodbJava: How to programmatically determine that a dataset does not match a normal distribution? - javaEnabling line break in a docbook listing and adding a line break character - docbookSEO Friendly URLs in Webforms vs MVC - seoAll Articles