1
這是我的索引文件,我想從fetch.php中獲取值。 $('#loader').html($(response).fadeIn('slow'));
這允許獲取所有的值並將其顯示在div = loader中。但我想要將單個返回值存儲爲javascript值。檢索Success函數中的多個值並將它們存儲到javascript變量
$.post("fetch.php?url="+$('#url').val(), {}, function(response){
//var $res=$(response);
//var title =$res.filter('.title').text(); (not wrking)
//$('#title').val(title);
$('#loader').html($(response).fadeIn('slow'));
$('.images img').hide();
$('#load').hide();
$('img#1').fadeIn();
$('#cur_image').val(1);
});
});
<input type="hidden" name="cur_image" id="cur_image" />
<div id="loader">
<div align="center" id="load" style="display:none"><img src="load.gif" /></div>
</div>
<input type="hidden" name="title" id="title" />
(e.g. I want to store the title value from fetch.php to this hidden field)
**fetch.php**
<div class="info">
<label class="title">
<?php echo @$url_title[0]; ?>
</label>
<br clear="all" />
<label class="url">
<?php echo substr($url ,0,35); ?>
</label>
<br clear="all" /><br clear="all" />
<label class="desc">
<?php echo @$tags['description']; ?>
</label>
<br clear="all" /><br clear="all" />
<label style="float:left"><img src="prev.png" id="prev" alt="" /><img src="next.png" id="next" alt="" /></label>
<label class="totalimg">
Total <?php echo $k?> images
</label>
<br clear="all" />
</div>
好的,謝謝。在我的PHP文件中,我回顯了4個值,所以我應該使用json。例如json_encode('title'=>'我的標題'),json_encode('description'=>'my_description')。 – user1525721 2012-07-14 15:46:52
不,只需將它們添加到傳遞給'json_encode'的數組中 - 所以'array('title'=>'your title','description'=>'your description');'。我更新了我的答案以反映這一點。 – Martin 2012-07-14 15:55:21