ASP.NET MVC 4 jQuery Ajax请求返回内部服务器错误 [英] Asp.net mvc 4 jquery ajax request return internal server error

查看:95
本文介绍了ASP.NET MVC 4 jQuery Ajax请求返回内部服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立对asp.net mvc控制器的ajax请求,但它给了我内部服务器错误

I tried to establish ajax request to asp.net mvc controller , but it give me internal server error

// My Products Controller
[HttpPost]
    public ActionResult FilterCategeory(int prodID) 
    {
        var categs = new Categ() {PROD_ID=prodID }.Search();
        return Json(categs);
    }

//My ajax request 
$("#categs").empty();
    var prm = $("#prods").val();
    $.ajax({
        type: "POST",
        url: '@Url.Action("FilterCategeory", "Products")',
        contentType: "application/json; charset=utf-8",
        data: {prodID: prm },
        dataType: "json",
        success: function (data)
        {
           alert('Success');
        },
        error: function () { alert('error');}
        });

推荐答案

ajax请求抛出无效的JSON原语异常.因此,使用 JSON.stringify(obj)

The ajax request throws Invalid JSON primitive exception. So Pass the data using JSON.stringify(obj)

Ajax请求

    var prm = $("#prods").val();
    var obj = { prodID: prm };
    $.ajax({
        type: "POST",
        url: '@Url.Action("FilterCategeory", "Home")',
        contentType: "application/json; charset=utf-8",
        data : JSON.stringify(obj),
        dataType: "json",
        success: function (data) {
            alert('Success');
        },
        error: function () { alert('error'); }
    });

选中此问题希望对您有所帮助.

您可以在Firefox或Chrome中检查错误类型 在Firefox中

You can check the error type in Firefox or Chrome In firefox

右键单击浏览器,然后单击检查元素.然后选择网络 标签.当您单击请求时,它将显示标题,Cookie等.从中选择响应".这样您就可以找到错误

Right click the browser click Inspect Element. Then selected the Network tab. When you click the request it will show header, cookies etc. From that choose Response. So you can found the error

镀铬

这篇关于ASP.NET MVC 4 jQuery Ajax请求返回内部服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆