当我点击一个按钮从另一个页面获取信息,然后填充一个文本框并显示该文本框并隐藏其上方的div时,它不起作用,get将转到该链接,Ive尝试过在$.get(url,function(d){
中发出提醒,但不提醒,这是我的javascript:
<!-- edit a status !-->
$('.update_status').on('click', function(e){
var theId = this.id;
var url = '<?php echo Config::get('URL'); ?>dashboard/timeline_status/' + theId;
$.get(url,function(d){
$('.timeline_status').hide();
$('.update_status_post').show();
$('.update_status_post_text').val(d);
},'json');
});
<!-- End edit a status !-->
<a class="update_status" href="javascript:void(0);" id="<?php echo System::escape($status->timeline_status_id); ?>"><li class="fa fa-edit"></li></a>
这是我的html以上面的javascript:
<!-- update post inputs !-->
<div class="update_status_post" style="display:none;">
<p>
<form method="POST" action="<?php echo Config::get('URL'); ?>dashboard/update_status/<?php echo System::escape($status->timeline_status_id); ?>" class="update_status_form">
<textarea name="new_status" class="col-sm-12 update_status_post_text" rows="5"></textarea>
<p><input type="submit" class="btn btn-success pull-right" name="submit" value="<?php echo System::translate("Update"); ?>"></p>
</form>
</p>
</div>
<!-- end update post inputs !-->
这是我的Chrome上的网络标签显示的内容:
Remote Address:[::1]:80
Request URL:http://localhost/github/techDirectory/techDirectory/dashboard/timeline_status/58
Request Method:GET
Status Code:200 OK
Response Headers
view source
Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection:Keep-Alive
Content-Length:9
Content-Type:text/html; charset=UTF-8
Date:Tue, 25 Aug 2015 12:12:22 GMT
Expires:Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive:timeout=5, max=81
Pragma:no-cache
Server:Apache/2.4.12 (Win32) OpenSSL/1.0.1l PHP/5.6.8
X-Powered-By:PHP/5.6.8
答案 0 :(得分:0)
解决方案1
因为预期的返回值是JSON
,所以jquery会将返回字符串解析为JSON。我们在变量d
中获得的值。要将JSON对象更改为字符串,请使用 JSON.stringify() 。
$.get(url,function(d){
$('.timeline_status').hide();
$('.update_status_post').show();
$('.update_status_post_text').val(JSON.stringify(d));
},'JSON');
解决方案2
获取数据类型text
。
$.get(url,function(d){
$('.timeline_status').hide();
$('.update_status_post').show();
$('.update_status_post_text').val(d);
},'text');