[英]how to retrieve the array which is send from controller to the view through ajax?
i am new in jquery and ajax. 我是jquery和ajax的新手。 I am really cant figured it out how can i show the array result send from the controller from json_encode.
我真的不知道如何显示从json_encode的控制器发送的数组结果。 Below is the code in controller:
下面是控制器中的代码:
Controller 控制者
$totaldata['data'] = array('totalscore' =>$totalscore,'totalwicket' =>$totalwicket,'totalover' =>$totalover,'totalextra' =>$totalextra);
$this->output->set_output(json_encode($totaldata));
Jquery jQuery的
$.ajax({
url: 'xxxxxxxxx',
type : 'POST',
data:{
xxxx : arrayValue,
id : matchid,
},
success: function(dataone){
//$('.addmatchsuccess').html(dataone).show();
//setTimeout(function() {location.reload() },3000);
}
});
Problem I want to get each array value to be placed in a input field in view ...which i couldnt figured out still how it gonna work. 问题我想让每个数组值放置在视图中的输入字段中……我仍然无法弄清楚它将如何工作。 Please any help will be appreciated.
请任何帮助将不胜感激。 Thank You
谢谢
Tell me if this worked for you. 告诉我这是否对您有用。
success: function(dataone){
var parsedJson = $.parseJSON(dataone);
var totalscore = parsedJson.totalscore;
var totalwicket = parsedJson.totalwicket
}
If the response is in the form of
string
then you need to parse it usingJSON.parse
else you can readkeys
fromobject
(dataone)如果响应为形式
string
,那么你需要用它来解析JSON.parse
否则,你可以阅读keys
从object
(dataone)
Try this: 尝试这个:
if (typeOf dataone === 'string') {
myData = JSON.parse(dataone)['data'];
} else {
myData = dataone['data'];
}
var totalscore = myData['totalscore'];;
var totalwicket = myData['totalwicket'];
var totalover = myData['totalover'];
var totalextra = myData['totalextra'];
You can do this: 你可以这样做:
success: function(dataone){
var json_response= eval('('+response+')');
var totalscore =json_response.totalscore
var totalwicket =json_response.totalwicket
var totalover = json_response.totalover
var totalextra = json_response.totalextra
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.