简体   繁体   中英

JSON parse error on ajax call

I have this javascript function that I use in an MVC project. It's been working fine, no code has changed, other than some nuget packages have been updated since the last time I tested it (not sure which ones). Now suddenly I'm getting a parse error . The parameter being passed is simply 'indoor' or 'outdoor', and just to make sure that had nothing to do with the issue, I hard-coded it instead of passing it, both with and without the JSON.stringify to see if that mattered, which it didn't. Any ideas why this is suddenly breaking?

    function LoadHobbies(category) {
        var data = {
            type: category
        };
        return $.ajax({
            type: 'post',
            contentType: 'application/json; charset=utf-8',
            url: '/Hobby/LoadHobbies',
            dataType: 'json',
            data: JSON.stringify(data)
        });
    }

Remote Address:[::1]:9925 Request URL:http://localhost:9925/Hobby/LoadHobbies Request Method:POST Status Code:302 Found Request Headersview source Accept:application/json, text/javascript, */*; q=0.01 Accept-Encoding:gzip, deflate Accept-Language:en-US,en;q=0.8 Connection:keep-alive Content-Length:17 Content-Type:application/json; charset=UTF-8 Host:localhost:9925 Origin:http://localhost:9925 Referer:http://localhost:9925/Account/Index User-Agent:Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36 X-Requested-With:XMLHttpRequest Request Payloadview source {type: "indoor"} type: "indoor" Response Headersview source Cache-Control:private Content-Length:162 Content-Type:text/html; charset=utf-8 Date:Sat, 10 Jan 2015 01:28:13 GMT Location:/Login/Index?ReturnUrl=%2fHobby%2fLoadHobbies Server:Microsoft-IIS/8.0 X-AspNet-Version:4.0.30319 X-AspNetMvc-Version:5.2 X-Powered-By:ASP.NET X-SourceFiles:=?UTF-8?B?RDpcVXNlcnNcQW5kcmV3XERvY3VtZW50c1xjb2RlXEhvYmJ5TWF0cml4U29sdXRpb25NVkNcSG9iYnlNYXRyaXhXZWJcSG9iYnlcTG9hZEhvYmJpZXM=?=

Sorry, I'm a moron. I had added a global authentication check a while back, and forgot to put an [AllowAnonymous] attribute on this controller. So I was right about it not reaching the breakpoint, and you were right about the redirect. Sorry I wasted everyone's time.

Thanks,

Andrew

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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