使用jQuery我正在进行ajax调用以将数据附加到某些输入字段,jquery正在更改DOM,但是在我点击它们之前,更改不会出现在输入中。
这是我的jquery代码:
var data_track = '';
var data_image = '';
var data_artist = '';
var data_album = '';
var data_duration = '';
var data_mbid = '';
if(data.track.name) {data_track = data.track.name;}else{ data_track = '';}
if(data.track.album) {data_image = data.track.album.image[3]['#text'];}else{ data_image = 'http://placehold.it/250x250';}
if(data.track.artist.name) {data_artist = data.track.artist.name;}else{ data_artist = '';}
if(data.track.album) {data_album = data.track.album.title;}else{ data_album = '';}
if(data.track.duration) {data_duration = data.track.duration;}else{ data_duration = '';}
if(data.track.mbid) {data_mbid = data.track.mbid;}else{ data_mbid = '';}
$('#track-name').val(data_track);
$('#image').val(data_image);
$('#image_preview').attr('src', data_image);
$('#artist').val(data_artist);
$('#album').val(data_album);
$('#duration').val(data_duration);
$('#mbid').val(data_mbid);
$('#results').html('');
答案 0 :(得分:0)
它对我有用:http://jsfiddle.net/b4revvz6/2/
检查您的data
对象;
答案 1 :(得分:0)
这个代码在ajax调用中有另一个问题,当我得分时$('#results').html('');
出于ajax,代码运行完美