2

I trying to create simple web app in mvc4.

In my view i used below scripts

<link href="~/Content/jquery.mobile-1.4.2.css" rel="stylesheet" />
<script src="~/Scripts/jquery-2.1.1.js"></script>
<script src="~/Scripts/jquery.mobile-1.4.2.min.js"></script>

And one simple button calling javascript function getWeather() when clicked.

<input type="button" data-icon="refresh" id="btnNewLoc" data-iconpos="notext" name="SaveButton" onclick="getWeather();" />

But my problem is when i clicked button is not hitting my below java script function.

<script type="text/javascript">
    function getWeather() {
        var URL = "/Weather/GetWeather/" + $("#Location").val();
        $.get(URL, function (data) {
            $("#Result").html(data);
        });
    }
</script>

Please guide me.

2 Answers 2

3

Never use inline javascript with jQuery Mobile, it will usually not work at all.

Do it directly with jQuery:

$(document).on('click', '#btnNewLoc', function(){ 
    var URL = "/Weather/GetWeather/" + $("#Location").val();
    $.get(URL, function (data) {
        $("#Result").html(data);
    });
});

Reason, inline javascript will usually not trigger when used with jQuery Mobile.

Sign up to request clarification or add additional context in comments.

3 Comments

thanqs lot dude. one more doubt. I developing my web app using mobile template in mvc. The issue is when i created view by keeping my Layout page which already contain bundling. The created view does not getting bundling defined in layout page.
Sorry could you clarify your question? I understand what you ware telling me but I don't understand what is the question?
0

Try this : repalce your input button code to following code :

 <input type="button" id="btnNewLoc" value="Save" name="SaveButton" />

then use this script :

<script language="javascript" type="text/javascript">
    $(document).ready(function () {
        $("#btnNewLoc").click(function () {
            var URL = "/Weather/GetWeather/" + $("#Location").val();
            $.get(URL, function (data) {
                $("#Result").html(data);
            });
        });
    });
</script>

Hopefully it works...!

Comments

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.