0

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"
}

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.

11
  • window.location.href = url; this redirects to the url so you should not be using it. Better use the video tag in partial view and then reload/refresh it with passing the json result Commented Mar 25, 2018 at 9:52
  • remove redirection, make use of AJAX call and do whatever you want with the data from your JSON. Commented Mar 25, 2018 at 9:54
  • sorry but i didnt get you sir Commented Mar 25, 2018 at 9:55
  • stackoverflow.com/questions/14419436/… Check this answer Commented Mar 25, 2018 at 9:55
  • @M Adeel Khalid sir How to perform ajax call based on my code?? Please guide me , Thank You. Commented Mar 25, 2018 at 9:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.