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!

Community
  • 1
  • 1
šljaker
  • 7,294
  • 14
  • 46
  • 80
  • 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...) – Tomas Aschan Apr 19 '11 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. – šljaker Apr 19 '11 at 16:38

1 Answers1

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>
šljaker
  • 7,294
  • 14
  • 46
  • 80