0

When I submit my form with jQuery:

$('#saveButton').click(function () {                
                if (true) {
                    $('#submitForm').submit();
                } 
            });

I get an error in the file jquery....min.js:

SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

I'm using asp.net MVC to generate the form:

@using (@Html.BeginForm("ActionName", "ControllerName", FormMethod.Post, new { id = "submitForm" }))

Submit Buttons. I am using the top one. The button one is not clicked when this happens:

<input type="button" id="saveButton" class="bigButton" value="Save" />
<input type="submit" id="submitRequestButton" class="bigButton" value="Submit" />

I look in the network tab on FF and I don't see a POST. How can I track down or narrow down what is causing this problem?

Update

The code in the console window is all I get and its pointing me to the minified jQuery lib:

/*! jQuery v2.1.0 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ !function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k="".trim,l={},m=a.document,n="2.1.0",o=function(a,b){return new o.fn.init(a,b)},p=/^-ms-/,q=/-([\da-z])/gi,r=function(a,b){return b.toUpperCase()};o.fn=o.prototype={jquery:n,constructor:o,selector:"",length:0,toArray:function(){return

...and this goes on for about 1000 more lines or so.

9
  • Can you post the json data or sample of it? Commented May 28, 2014 at 15:35
  • Did you see the console for javascript error? Commented May 28, 2014 at 15:35
  • I don't see any JSON data and I have no idea how I can obtain it without the POST information in the Network tab. The console info is gibberish to me, I posted a short sample. Commented May 28, 2014 at 15:38
  • can you show you complete view with jquery include code? Commented May 28, 2014 at 15:38
  • Is your submit button part of the form? Had this problem myself a couple of days ago. Commented May 28, 2014 at 15:38

1 Answer 1

2

I fixed the problem by removing the MVC validation scripts and my own custom validation scripts from the code:

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/conditional-validation.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/customItemRequestValidation.js")" type="text/javascript"></script>

I wrote new custom validation that is not based on MVC's validation. I have no need for MVC's built in validation. I don't know why one of these files is causing a JSON parse error.

The old custom validation scripts that I removed did stuff like:

$.validator.addMethod('requiredif',

and

$.validator.unobtrusive.adapters.add(
    'requiredif',

My guess is one of my old custom validation scripts was messed up or my new validation scripts conflict with MVC's validation scripts somehow.

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

1 Comment

i think these validation codes from different place conflict.

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.