Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net NET MVC 3:jQuery$.get(url、数据、回调、类型)_Asp.net_Asp.net Mvc 3_Jquery - Fatal编程技术网

Asp.net NET MVC 3:jQuery$.get(url、数据、回调、类型)

Asp.net NET MVC 3:jQuery$.get(url、数据、回调、类型),asp.net,asp.net-mvc-3,jquery,Asp.net,Asp.net Mvc 3,Jquery,我正在尝试根据另一个选择列表中的选择动态更新选择列表。jQuery代码 <script type="text/javascript"> // Respond to Category selection $('#selectCategory').change(function () { // Ajax call to 'Specialties' action method with parameter searchType $.get('

我正在尝试根据另一个选择列表中的选择动态更新选择列表。jQuery代码

<script type="text/javascript">
    // Respond to Category selection
    $('#selectCategory').change(function () {
        // Ajax call to 'Specialties' action method with parameter searchType
        $.get('@Url.Action("Products", "Product")',
                { "parameter1": $(this).val(), "parameter2": null }, 
                function (data) {
                    $('#products').html(data); 
            });
    });
</script>
景色

   <div id="products">
        @Html.Partial("_Products")
   </div>
局部视图

@model MyMVC3App.Models.MyViewModel

<select mid="productSelect" name="@ClarusConstants.PropertyNames.Specialty" > 
    <option value="0">@Resources.LabelText_SelectASpecialty</option>
        foreach (Product p in Model.Products)
        {
        <option value="@Product.ID" name="@product.Description</option> 
        }
</select>
动作法

public ActionResult Specialties(string parameter1, string parameter2)
{
    List<Product> products = myDB.Products.Where(p => p.Category == parameter1).ToList();
    ViewModel myViewModel = new ViewModel();

    viewModel.Products = products;

    if (Request.IsAjaxRequest())
    {
        return PartialView("_Products", myViewModel);
    }
    else
    {
        return View(myViewModel);
    } 
}
回调正在命中正确的操作方法,并且正在检测ajax请求。不幸的是,products div的内容InnerHTML并没有被替换,所以这一切都是徒劳的


提前感谢您的帮助。

因此,如果您更换了$'products'。htmldata;当警报包含一些静态文本时,警报会在预期时弹出?当您谈到检测到ajax请求时,并不完全清楚您的意思。@标记M:当我替换$'products'。htmldata;使用任何一种警报数据;或警告“废话”;未显示警报。发送ajax请求的url的域是否与接收请求的url的域相同?@Mark M:域是localhost,url是操作方法。正在调用操作方法。.get在响应中失败,而不是在请求中失败。回调函数未被执行。您能否从中接受的答案实现ajax错误报告,并查看是否收到错误警报?