Abhijeet Panpatil

Abhijeet Panpatil

  • NA
  • 95
  • 20.7k

Storing JSON response in variable

Mar 25 2018 5:42 AM
I'm calling an API on button click which returns me the response in JSON format.
 
My code for calling API is as follows:
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<div id="dropdown">
<span class="list">
<select id="itemList">
<option value="select">Select</option>
@foreach (var item in Model)
{
<option value="@item">@item</option>
}
</select>
</span>
<span class="button">
<button type="button" id="btn">Watermark</button>
<script type="text/javascript">
$(function () {
$("#btn").bind("click", function () {
var url = "http://104.211.243.204/?container=comedy-movies&blob=" + encodeURIComponent($("#itemList").val());
window.location.href = url;
});
});
</script>
</span >
</div >
 
Now after execution it redirects me to the url and on that window it shows me the output. Now i want to use that output in another logic. So i want to store that json response in client side into a variable without redirecting me to that url. Please help me regarding this.
 
This is the output from API:-
 
{ "url": "https://moviestarstorage.blob.core.windows.net/water/gol.mp4" }
pasting
 
Now i want to store this result into a variable at client side and used that variable to video tag. API returns me the result of video. Please help me regarding this. I'm using the c# Model View Controller for this
 
Please help me regarding this. I have search for many solutions but no one work for me . So if there is any way to do this please help me regarding that. Waiting for positive reply.
 
I want to display that video in my view page. json gives the url og video. So i want to store that video url at client side. and display in html so i can take that variable which holds the url of video and im pass it to the video tag.

Answers (6)