繁体   English   中英

在Visual Studio 2010中使用jQuery缺少Ajax的Intellisense

[英]Intellisense missing for ajax with jQuery in Visual Studio 2010

我是ASP.NET的新手,正在制作一个网站,我需要ajax来做某事。 但是,当我尝试在jQuery中调用ajax时,它不会出现在$.之后$. 标志。 我已经下载了最新版本的jQuery。 我正在使用Visual Studio 2010。

我为我的问题拍了张照片。 我在上面尝试了一些解决方案,但是ajax仍然无法正常工作。 我的问题的图片

此示例可帮助您入门。 这可以是您的看法:

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index28</title>
    @*the next line should point to your jquery*@
    <script src="~/Scripts/jquery-1.12.4.min.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#create").click(function () {
                var MyModel = {
                    ArticleName: $("#articleName").val(),
                    CountField: $("#countField").val(),
                    PriceField: $("#priceField").val()
                }
                $.ajax({
                    url: '/Home/GoIntoMethod',
                    type: 'POST',
                    data: MyModel,
                    dataType: 'json',
                    success: function (result) {
                        $("#targetName").val(result.targetName);
                        $("#targetCount").val(result.targetCount);
                        $("#targetPrice").val(result.targetPrice);
                    },
                    error: function (data, status, error) {
                        //alert("error");
                    }
                });
            })
        })
    </script>
</head>
<body>
    <div>
        @*you can make these field using html helper*@
        <input type="text" id="targetName" />
        <input type="text" id="targetCount" />
        <input type="text" id="targetPrice" />
    </div>
    <div class="row">
        <input id='create' type="submit" value="Save" />
    </div>
</body>
</html>

这是控制器:

public class HomeController : Controller
{
    [HttpPost]
    public ActionResult GoIntoMethod() 
    {
        //put a breakpoint here to see you can do whatever you want with the fields
        return Json(new
        {
            targetName = "aName",
            targetCount = "4",
            targetPrice = "2.37"
        }
         , @"application/json");
    }

    public ActionResult Index28(int? id)
    {
        return View();
    }

谢谢大家对我的帮助。 我找到了解决我问题的方法。 我在Google上搜索jquery的旧版本(1.8.0),然后将所有代码复制到该jquery中,然后将其粘贴到我的jquery文件中。 之后,我可以打电话给ajax。 我的照片

暂无
暂无

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

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