Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 141864

Using JavaScript how do I sent JSON from Razor page to Controller in MVC .NET Core

$
0
0

I have a razor page with the following JavaScript code that gets the JSON object. From this code, how can I send the JSON object to a controller? (MVC Core.NET 3.0)

I now this sounds crazy - the only reason I'm doing this is to demo this project for Charles Proxy training - I've written a controller that can get the JSON data from the API - the problem is Charles Proxy can only intercept the data if I run the app locally - and in training others in class won't be able to do that, therefore I have the need to get the JSON object via the client and send it to the server.

Thank you very much in advance :-)

<script>
var xhr = new XMLHttpRequest();
var url = "https://cors-anywhere.herokuapp.com/https://www.511virginia.org/data/geojson/icons.rwis.geojson";


xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {            
        var jsonData = JSON.parse(xhr.responseText);           
        showWeather(jsonData);
    }
};
xhr.open("GET", url, true);
xhr.send();

function showWeather(data) {
    var output = "<ul>"; 
    var i;
    // validate obj has data
    //for (var i in data.features) {
     //  output += "<li>" + data.features[i].id  + "</li>";
    //}
    output += "</ul>"; 
    document.getElementById("wxList").innerHTML = output;


}</script>

Viewing all articles
Browse latest Browse all 141864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>