簡體   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