简体   繁体   English

MVC-点击没有任何反应(视图中的Jquery)

[英]MVC - nothing happens on click (Jquery in view)

I want my button to do something onClick() , it has the ID btnSend . 我希望我的按钮执行onClick() ,它的ID为btnSend But nothing happens when I click the button which is weird and I can't figure out why. 但是,当我单击奇怪的按钮时却什么也没有发生,我不知道为什么。

  • The script is in my view for now within script tags. 我目前认为该脚本位于脚本标签中。

     $("#btnSend").click(function () { var messageInfo = { "Body": $("#Message").val(), }; $.ajax({ type: "POST", url: '/Api/Posts', data: JSON.stringify(messageInfo), contentType: "application/json;charset=utf-8", processData: true, success: function (data, status, xhr) { alert("The result is : " + status); }, error: function (xhr) { alert(xhr.responseText); } }); }); 

Are you sure your script is running after the page is loaded? 您确定页面加载后脚本正在运行吗?

Put your script at the bottom of the page and give it a try. 将您的脚本放在页面底部,然后尝试一下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM