$(document).ready(function(){
$('#bill_no').blur(function(){
if( $('#bill_no').val().length >= 3 )
{
var bill_no = $('#bill_no').val();
getResult(bill_no);
}
return false;
})
function getResult(billno){
var baseurl = $('.hiddenUrl').val();
// $('.checkUser').addClass('preloader');
$.ajax({
url : baseurl + 'returnFromCustomer_Controller/checkBillNo/' + billno,
cache : false,
dataType: 'json',
success : function(response){
$(".text").prepend(response.text);
}
})
}
})
我的控制器
function checkBillNo($billno){
$this->load->model('returnModel');
$query = $this->returnModel->checkBillNo($billno);
header('Content-Type: application/x-json; charset=utf-8');
echo(json_encode($this->returnModel->sale($billno)));
}
从控制器获取值后,如何打印 SPAN 类"文本"中的值.. 我已经在 Firebug 中检查了响应选项卡中我成功获得结果,但我如何在 SPAN 类的视图页面中打印..
您需要
获得这样的响应objet.parameter
:
success : function(response)
{
$(".text").html(response.result);
}
因为正如您在评论中所说:
这是响应 {"结果":"142"}
success : function(response)
{
$(".text").html(response);
}
您可以使用段 no 从 url 检索参数
function checkBillNo($billno)
{
$this->load->model('returnModel');
$query = $this->returnModel->checkBillNo($billno);
$billno = $this->uri->segment(3);
$billno_results = $this->returnModel->sale($billno)
//header('Content-Type: application/x-json; charset=utf-8');
echo json_encode($billno_results);
}
这里$query有什么用。此外,您无需设置标头类型
在这里查看您的 ajax
$.ajax({
url : baseurl + 'returnFromCustomer_Controller/checkBillNo/' + billno,
cache : false,
dataType: 'json',
success : function(response){
$(".text").prepend(response);
}
})
看到您不需要响应。文本 简单的打印响应