I've created a basic weather forecast app. What im struggling to do is get the citys value from the input field, into my script. This is on my View:
So if the user types the city 'London' for example, script code passes 'London' as a parameter. How can i achieve this? I understand I must construct the URL using JavaScript but unsure how to.
ViewBag.Title = "WeatherOrNot";
}
<h2>WeatherJS</h2>
<p id="reply"></p>
<p id="temp"></p>
<p id="humidity"></p>
<form>
City:<br>
<input id="city" type="text" name="city"><br>
</form>
<button>Get Weather</button>
<script>
$(document).ready(function () {
$("button").click(function () {
$.get("@Url.Action("GetWeather","Home",new {City = "Mumbai" })", function (response) {
//response
$("#reply").text(response.name);
$("#temp").text(response.main.temp);
$("#humidity").text(response.main.humidity);
//$("#city").get("city");
console.log(response);
});
});
});
I'm fairly new to MVC so apologies if this is very simple!
Thanks