1

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=?=

13
  • What error is it? Client side or server side. Please post the erro. Commented Jan 9, 2015 at 23:47
  • It's a javascript error that only shows if I use a .fail() from where I call this. It never calls the controller on the server. Commented Jan 9, 2015 at 23:52
  • Can you check the network tab on the browser to verify it's not doing a call to the server? Commented Jan 9, 2015 at 23:54
  • Try this instead of data: '{ "type" : ' + category + ' }';. This is an obscure case, make sure data variable is not duplicated or at least change its name to _data Commented Jan 9, 2015 at 23:59
  • whatever the server is returning isnt valid json Commented Jan 9, 2015 at 23:59

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.