Render json response from controller to view
I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?
"{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"
respond_to do |format|
format.json { render :json => result }
end
ruby-on-rails
add a comment |
I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?
"{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"
respond_to do |format|
format.json { render :json => result }
end
ruby-on-rails
add a comment |
I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?
"{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"
respond_to do |format|
format.json { render :json => result }
end
ruby-on-rails
I am working in web services applications which already exist.I am getting below response and saving response in result in controller.I need to show this as table format like,Status Code,Parameters, and response.How to bring json response to view as table in rails?
"{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}"
respond_to do |format|
format.json { render :json => result }
end
ruby-on-rails
ruby-on-rails
edited Jan 3 at 9:38
Lenin Raj Rajasekaran
16.1k1173116
16.1k1173116
asked Jan 3 at 9:34
Raja1983Raja1983
237
237
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:
var tr = '<tr><td>';
tr += jsonResponse.firstAttribute;
tr += '</td><td>';
tr += jsonResponse.secondAttribute;
tr += '</td>';
...
$('#you-table-body-id').append(tr);
by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.
Thanks for your input.
– Raja1983
Jan 3 at 16:35
add a comment |
The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:
JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")
This will change it to:
{"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}
You can render is as json:
respond_to do |format|
format.json { render json: JSON.parse(result) }
end
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
|
show 12 more comments
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019543%2frender-json-response-from-controller-to-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:
var tr = '<tr><td>';
tr += jsonResponse.firstAttribute;
tr += '</td><td>';
tr += jsonResponse.secondAttribute;
tr += '</td>';
...
$('#you-table-body-id').append(tr);
by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.
Thanks for your input.
– Raja1983
Jan 3 at 16:35
add a comment |
There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:
var tr = '<tr><td>';
tr += jsonResponse.firstAttribute;
tr += '</td><td>';
tr += jsonResponse.secondAttribute;
tr += '</td>';
...
$('#you-table-body-id').append(tr);
by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.
Thanks for your input.
– Raja1983
Jan 3 at 16:35
add a comment |
There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:
var tr = '<tr><td>';
tr += jsonResponse.firstAttribute;
tr += '</td><td>';
tr += jsonResponse.secondAttribute;
tr += '</td>';
...
$('#you-table-body-id').append(tr);
by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.
There are lots of better options using js libraries, but if you want to just use jquery, you should create the table using plain HTML (giving an id to the tbody). Then use js to create a string and concatenate it with every attribute you need, for instance:
var tr = '<tr><td>';
tr += jsonResponse.firstAttribute;
tr += '</td><td>';
tr += jsonResponse.secondAttribute;
tr += '</td>';
...
$('#you-table-body-id').append(tr);
by doing so you will concatenate this chunk of html containing the data you want to exhibit in your site.
answered Jan 3 at 15:41
Rodrigo EcheconeaRodrigo Echeconea
963
963
Thanks for your input.
– Raja1983
Jan 3 at 16:35
add a comment |
Thanks for your input.
– Raja1983
Jan 3 at 16:35
Thanks for your input.
– Raja1983
Jan 3 at 16:35
Thanks for your input.
– Raja1983
Jan 3 at 16:35
add a comment |
The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:
JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")
This will change it to:
{"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}
You can render is as json:
respond_to do |format|
format.json { render json: JSON.parse(result) }
end
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
|
show 12 more comments
The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:
JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")
This will change it to:
{"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}
You can render is as json:
respond_to do |format|
format.json { render json: JSON.parse(result) }
end
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
|
show 12 more comments
The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:
JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")
This will change it to:
{"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}
You can render is as json:
respond_to do |format|
format.json { render json: JSON.parse(result) }
end
The response you are saving in controller is in string format. To render it as JSON,You first need to parse it to JSON as following:
JSON.parse("{"statusCode":200,"parameters":[{"name":"Device.Description","value":"Gateway Device","dataType":0,"parameterCount":1,"message":"Success"}]}")
This will change it to:
{"statusCode"=>200, "parameters"=>[{"name"=>"Device.Description", "value"=>"Gateway Device", "dataType"=>0, "parameterCount"=>1, "message"=>"Success"}]}
You can render is as json:
respond_to do |format|
format.json { render json: JSON.parse(result) }
end
answered Jan 3 at 9:57
Talha JunaidTalha Junaid
230210
230210
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
|
show 12 more comments
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
ok Thanks.Now displaying response in text area.I need to change as table format like status code ,Parameters.How to bring this as html table format?
– Raja1983
Jan 3 at 10:01
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
You want to show it in table?
– Talha Junaid
Jan 3 at 10:17
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
yes.I want show as table.
– Raja1983
Jan 3 at 10:26
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
You are using javascript to call this JSON returning action?
– Talha Junaid
Jan 3 at 10:31
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
yes.We are using java script.
– Raja1983
Jan 3 at 10:32
|
show 12 more comments
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019543%2frender-json-response-from-controller-to-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
