51

I'm trying to send a call using Ajax but in Chrome it is rising error but in Firefox there is no error. But still it can't calling the method. I tried to record my call in Firebug but there is no call request in Firebug. So that's the reason there is no error in Firefox.

Index.chshtml code is below

function onLoad(e) {

    var grid = $(this).data("tGrid");
    //bind to the context menu of the Grid's header
    event.preventDefault();
    $(this).find(".t-grid-header").bind('contextmenu', function (e) {
        //wait for the menu to be generated
        setTimeout(function () {
            // bind to the checkboxes change event. The context menu has ID in the format "GridName" + "_contextmenu"
            $('#globalsearchgrid_contextMenu :checkbox').change(function () {
                debugger;
                var $checkbox = $(this);
                // the checked state will determine if the column has been shown or hidden
                var checked = $(this).is(":checked");
                // get the index and the corresponding column from the Grid's column collection
                var columnIndex = $(this).data("field");

                var request = "{'columnIndex':'" + columnIndex + "'value':'" + checked + "'}";
                $.ajax({
                    type: "POST",
                    url: "../../GlobalSearch/SaveColumnInfo",
                    data: request,
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: function (msg) { },
                    error: function (xhr, status, error) {
                        alert(error.responseTextss);
                    }

                });
            });
        });
    });
}

Controller method

 public JsonResult SaveColumnInfo(string columnIndex, string value)
    {
        CookieHelper helper=new CookieHelper();
        helper.UpdateCookie(int.Parse(columnIndex), value.ToString());

        return Json("Success");
    }

Error in Chrome

POST http‍://localhost:3577/GlobalSearch/SaveColumnInfo 500 (Internal Server Error)
jQuery.ajaxTransport.send
jQuery.extend.ajax
(anonymous function)
jQuery.event.handle
jQuery.event.add.elemData.handle.eventHandle

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Haris
  • 1,179
  • 7
  • 15
  • 32
  • You are doing a post. Did you mark SaveColumnInfo as HttpPost? – Fals Oct 04 '13 at 12:04
  • Yes, I've tried with HttpPost but no success. In other pages of mu application I'm using the same ajax call method without HttpPost attribute and its working if fine at ther. – Haris Oct 04 '13 at 12:09
  • I'dont think so, ../../GlobalSearch/SaveColumnInfo is wrong! You cant type this kind of url! /GlobalSearch/SaveColumnInfo should work! – Fals Oct 04 '13 at 12:38
  • well in other calling method I'm using the same and it is correct. However I've used without ../.. it is also working. But still same erro. I'm editing my question for error detail. – Haris Oct 04 '13 at 12:57
  • There is issue with my value string. Thanx Fals for your help. – Haris Oct 04 '13 at 13:10
  • This question appears to be off-topic because it is too localized. – casperOne Oct 04 '13 at 18:40

1 Answers1

71

The 500 code would normally indicate an error on the server, not anything with your code. Some thoughts

  • Talk to the server developer for more info. You can't get more info directly.
  • Verify your arguments into the call (values). Look for anything you might think could cause a problem for the server process. The process should not die and should return you a better code, but bugs happen there also.
  • Could be intermittent, like if the server database goes down. May be worth trying at another time.
Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
asantaballa
  • 3,919
  • 1
  • 21
  • 22
  • 1
    I changed my fancy names for id being passed to just "id" and mine worked. go figure – JustJohn Mar 24 '16 at 06:12
  • 2
    In my case, I clicked on the error that was showing in console i.e. http://vuela.dev/api/calendar/create 500 (Internal Server Error). clicking it, I was taken to Network tab where it showed different files, their statuses, sizes and all that stuff. then i clicked on a file that had 500 status & it showed me error details from where I figured there was a constructor running with bad credentials. NOTE: I am using Laravel 5.4 – Lahori Jul 04 '17 at 07:50
  • 4
    Spent 30mins with this to only find out that: that data name in the Ajax, must be the same with the variable name you use in your controller. if not specify it like `data: {columnindex: request}` – wolfQueen Jan 18 '18 at 03:12
  • solution #1: Install the required packages by running the composer command from the the root of the project: sudo composer install solution #2: For solving the problem i ran the following commands through terminal. sudo chmod -R 755 MYlaravel_project and then type below to allow laravel to write file to storage folder chown -R www-data:www-data /path/to/your/root/dir/ chmod -R 775 /bootstrap chmod -R 775 /storage – SyedAsadRazaDevops Apr 17 '22 at 09:48
  • 1
    id which was an INT was null and asp-route-id was throwing an exception on the server in my case – Qwerty Jun 25 '22 at 07:21