【问题标题】:Intellisense missing for ajax with jQuery in Visual Studio 2010在 Visual Studio 2010 中使用 jQuery 的 ajax 缺少 Intellisense
【发布时间】:2017-06-05 17:31:28
【问题描述】:

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

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

【问题讨论】:

  • 所以你的意思是说你没有得到智能感知?
  • VS 2010 for Javascript 中的智能感知不是很好。如果您期望它的行为与您编写 C# 代码时一样好,那么这不会发生。如果您只是拨打$.ajax(...); 会发生什么?
  • 想想,有些人(像我一样)实际上在没有智能感知/代码完成的情况下编写了代码......
  • 谢谢你的帮助我去试试

标签: javascript jquery asp.net visual-studio


【解决方案1】:

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

<!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();
    }

【讨论】:

  • 我想我的问题是我在下面放了一批javascript代码
【解决方案2】:

感谢大家帮助我。我找到了解决我的问题的方法。我在谷歌上搜索 jquery 旧版本(1.8.0),然后复制该 jquery 中的所有代码,然后将其粘贴到我的 jquery 文件中。之后我可以调用 ajax.My picture

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-27
    • 2012-09-27
    • 2011-07-20
    • 2011-04-30
    • 2019-03-22
    • 2011-12-03
    • 2016-06-15
    • 2015-04-20
    相关资源
    最近更新 更多