1

I'm using ASP.NET MCV3, jquery 1.5.2 and jquery form plugin.
Here's the sample code:

<script type="text/javascript">
    // wait for the DOM to be loaded
    $(document).ready(function () {
        $('#uploadForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function () { alert('beforeSubmit'); },
            success: function() { alert('success'); },
            error: function () { alert('error'); }
        });
    });
</script>

<form id="uploadForm" action="@Url.Action("UploadFile")" method="post"> 
    <input type="submit" value="Submit file" /> 
</form>

[AcceptVerbs(HttpVerbs.Post)]
public JsonResult UploadFile()
{
    return Json(new { message = "success" });
}

When I submit the form, I always get the following error message: Expected ';'
I searched SO, Google.. but couldn't find any solution to this problem.

I found Darin's comment here, but I need to have beforeSubmit and success events.

Any help would be greatly appreciated!

2
  • Is your problem solved? If so, I'd recommend you post the solution as an answer to your own question, and mark it the solution. (There are time limits on when you can do this, so you might have to wait a couple of days before you can tick in the green checkmark...) Commented Apr 19, 2011 at 15:39
  • @Tomas, yes, problem is solved. I have to wait a couple of days before I can answer to my question. If someone has a better answer, I would gladly accept his/hers answer. Commented Apr 19, 2011 at 16:38

1 Answer 1

0

I changed dataType from json to text and then I parsed the result. Everything seams to work ok.

<script type="text/javascript">
    // wait for the DOM to be loaded
    $(document).ready(function () {
        $('#uploadForm').ajaxForm({
            dataType: 'text',
            beforeSubmit: function () { alert('beforeSubmit'); },
            success: processJson,
            error: function () { alert('error'); }
        });
    });

    function processJson(responseJson) {
        var obj = jQuery.parseJSON(responseJson);
        alert(obj.message);
    }
</script>
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.