input src data from json

2019-09-22 10:32发布

问题:

I got a very similar question here: jQuery progressbar with ajax request to json

Can you help me here with a solution?

I try to get the path out of a *.json file and use it for an "input image field" with jquery.

HTML

<input id="pic_1" type="image" src="<!-- what to do here? -->" /> 

JS

$(function() {
    $.ajax({ dataType:"json",
        url: test.json, 
        success: <!-- what to do here? -->,
    });
});

test.json

{ "pic_1":"img/test.png" }

would be glad for similar solution, due to jQuery progressbar with ajax request to json !

Thank you

回答1:

Why don't you use $.getJSON() http://api.jquery.com/jquery.getjson/