我最近将jQuery从1.8升级到2.1.我突然发现.live()停止工作.
我收到了错误TypeError: $(...).live is not a function.
有什么方法可以用来代替.live()吗?
我使用Visual Studio 2012中的模板创建了一个新的ASP.Net MVC 4项目.升级到jQuery 1.9后,登录功能中断.具体来说,我得到了错误
0x800a138f - JavaScript运行时错误:无法获取未定义或空引用的属性"调用"
在第1172行,jquery.validate.js中的第5列
我该如何解决这个问题?
关于Ajax.BeginForm的问题有很多关于使用返回局部视图正确更新目标元素的问题:
mvc4 ajax更新同一页面
ASP.NET MVC 4 - Ajax.BeginForm和html5
MVC 4(razor) - 控制器是返回部分视图但整个页面正在更新
MVC 4 Ajax没有更新页面中的PartialView
但是,所有这些都可以通过手动写出jQuery ajax或包含丢失的javascript文件来回答.
@using (Ajax.BeginForm("PostcardDetails", new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "details"
}))
{
<div id="PostcardSearchResults">
@{Html.RenderAction("PostcardSearchResults", Model);}
</div>
}
<div id="details">
</div>
Run Code Online (Sandbox Code Playgroud)
相关控制器代码:
[AcceptVerbs(HttpVerbs.Post | HttpVerbs.Get)]
public ActionResult PostcardSearchResults(PostcardSearchFilter filter)
{
PostcardSearchResults model = new PostcardSearchResults(filter);
return PartialView("_PostcardSearchResults", model);
}
Run Code Online (Sandbox Code Playgroud)
在我的布局中,我引用了这些jQuery文件.此外,我已经验证页面正在输出正确的路径,并且它找到了正确的文件.我试着开关的顺序unobtrusive-ajax.min.js和validate.min.js,没有成功.
<script type="text/javascript" src="@Url.Content("~/Scripts/globalize.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.9.1.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery-ui-1.10.0.custom.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")"></script> …Run Code Online (Sandbox Code Playgroud) 使用ASP.NET MVC 4和NuGet管理包.
升级到jQuery 1.9.1via后NuGet,我开始收到JavaScript关于删除live()函数的错误jQuery 1.9.x.
我点击F5从VS.NET运行调试模式,进入登录页面,得到以下信息:

发现这个StackOverflow答案:https://stackoverflow.com/a/14512797 并进行了4次更改~\Scripts\jquery.unobtrusive-ajax.js.
我的~\Scripts\jquery.unobtrusive-ajax.js:
$(document).on("click", "a[data-ajax=true]", function (evt) {
...
});
$(document).on("click", "form[data-ajax=true] input[type=image]", function (evt) {
...
});
$(document).on("click", "form[data-ajax=true] :submit", function (evt) {
...
});
$(document).on("submit", "form[data-ajax=true]", function (evt) {
...
});
Run Code Online (Sandbox Code Playgroud)
我也物理删除jquery.unobtrusive-ajax.min.js并用于WebGrease 1.3.0从我的更新中重新生成它~\Scripts\jquery.unobtrusive-ajax.js.
但是,出于某种原因,我对不使用该.live()功能的更改并不坚持.我尝试停止运行MVC应用程序的IIS Express 8.0网站(localhost:63798).
在尝试再次运行F5以在调试模式下运行之前,还尝试执行Build-> Clean Solution,Build-> Rebuild Solution.
如果有人以前经历过这个并且有任何见解,我将非常感激.先感谢您.
asp.net-mvc jquery asp.net-mvc-4 unobtrusive-ajax visual-studio-2012
我对以下代码有问题。console.log输出为:
我通过 JavaScript Ajax 请求请求的 URL 是“login.php”:
<?php include('init.php');
use Login\LoginService;
#include(__DIR__.'/Login/LoginService.php');
global $pdo;
session_start();
$username = $_POST['username'];
$pass = $_POST['password'];
if (!empty($username)) {
$test = new LoginService();
$user = $test->getUsersLogin($username);
if (!empty($user) && $user[0]['login'] == $username) {
$json = json_encode(array("success" => 1));
echo $json;
} else {
$json = json_encode(array("success" => 0));
echo $json;
}
}
?>
Run Code Online (Sandbox Code Playgroud)
我通过 JavaScript 发出的 Ajax 请求:
$(() => {
$('.login-form').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: "POST",
dataType: "json",
timeout: 500,
url: …Run Code Online (Sandbox Code Playgroud) 我想使用Ajax.ActionLink Html助手,因此我需要jquery.unobtrusive-ajax.min.js库,但IE总是显示此错误:
Microsoft JScript运行时错误:无法设置属性'unobtrusive'的值:object为null或undefined
我已经读过解决方案是使用jquery.validate.min.js和jquery.validate.unobtrusive.min.js,但后来我无法识别服务器端的ajax调用.
jquery ×4
ajax ×2
javascript ×2
asp.net-mvc ×1
c# ×1
deprecated ×1
function ×1
json ×1
live ×1
php ×1
razor-2 ×1