Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi experts,
JQuery returns error: 'Error in loading...' But the controller works fine.

JQuery passes value to controller perfectly and the controller returns fine but there is still an error.

I don't know what's wrong with this.
Please help me!

Controller:
C#
[HttpPost]
public ActionResult EditNews(string value)
{
    long id = long.Pars(value);
    News news = ....//Some query that returns a valid news
    return PartialView(news);
}


View:
HTML
@model MyProject.ViewModels.NewsViewModel

@Html.ListBoxFor(m => m.SelectedNews, Model.News,
new {id="newsListBox", size=10 ,data_url = Url.Action("EditNews", "News" ) })


And JQuery function:
JavaScript
$(function () {
    $('#newsListBox').change(function () {
        var selectedValue = $(this).val();
        $.ajax({
            url: $(this).data('url'),
            dataType: 'text',
            type: 'POST',
            cache: false,
            data: "value=" + selectedValue,
            success: function (result) {
                 alert('It's fine');
            },
            error: function (result) {
                alert('Error in loading...');
            }
        });
    });
});
Posted
Comments
Kornfeld Eliyahu Peter 26-Oct-14 16:30pm    
How did you decided that the controller works perfectly - the ajax call fails after all...
The full parameter format of the error method is like this: Function( jqXHR jqXHR, String textStatus, String errorThrown ) - http://api.jquery.com/jQuery.ajax/
This can help you to find the exact error...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900