我有一个母版页,按此顺序声明<script>
标记:
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/bundles/jquery")
</head>
<body style= "margin-left: 40px; margin-top: 30px;">
@{ Html.RenderPartial("_Login"); }
@RenderBody()
@RenderSection("scripts", required: false)
</body>
</html>
我有一个局部视图,我在其中一个视图中加载:
@using(var form = @Html.BeginForm("RequestNewVerificationCode", "Account", FormMethod.Post, new { name = "frmRequestNewVerificationCode" }))
{
<fieldset>
<p>
Email
@Html.TextBox("Email", null, new { id = "txtEmail" })
<input type="button" value="Request New Verification Code" id="btnRequestNewVerificationCode" />
</p>
</fieldset>
<p>
<div id= "divMessage"></div>
</p>
}
@Scripts.Render(@Url.Content("~/Scripts/RequestNewVerificationCode.js"))
我RequestNewVerificationCode.js
的内容如下:
$(document).ready(RequestNewVerificationCode.WireHandlers);
var RequestNewVerificationCode =
{
WireHandlers : function()
{
debugger;
$("#btnRequestNewVerificationCode").bind("click", this.MakeAjaxRequest);
},
url: '/Account/RequestNewVerificationCode',
MakeAjaxRequest: $.ajax(url,
{
cache: false,
async: false,
type: 'POST',
data: JSON.stringify(
{
'Email': $("#txtEmail").val()
}),
dataType: 'json',
contentType: 'application/json',
success: OnSuccess,
error: OnError
}),
OnSuccess: function(data, textStatus, jqXHR) {
},
OnError: function (jqXHR, textStatus, errorThrown) {
}
};
然而,我放入JS文件的断点根本没有被击中。我甚至无法调试它。
答案 0 :(得分:2)
啊,明白了。这个总是咬我的。
我现在回想一下,在JavaScript中,如果你使用我正在使用的语法声明一个对象,即如果你说:
var foo = { }; // this syntax
而不是这一个:
var foo = new object();
然后,在声明它之前你不能使用foo,即JavaScript将不提升该符号。所以:
foo.bar() // illegal because foo not yet declared
var foo = { }; // this syntax
,而:
foo.bar(); // legal
var foo = new object(); // this syntax