2

I'm currently getting the error Object #<Object> has no method 'toUpperCase' before the POST request is made, so I would like and appreciate a lot your help! Thanks

function ajaxeo(url, data, method){
    $.ajax({
        url: url,
        type: method,
        data: data,
        success: function(response){
            alert(response);
        }
    });
}

function cambio(ID, newValue){
ajaxeo("includes/php/ajax/changeProvider.php?oldID="+ID, "post", {"newVal": newValue});
}

var editable = $('div[contentEditable][dataAjax]');
for (var i=0, len = editable.length; i<len; i++){
    editable[i].setAttribute('data-orig',editable[i].innerHTML);
    editable[i].onblur = function(){
        if (this.innerHTML == $(this).attr('data-orig')) {
            // no change
        }
        else {
            // change has happened, store new value
            $(this).attr('data-orig', $(this).html())
            cambio($(this).attr('dataId'), $(this).html());
        }
    };
}

SaveChanges will throw a System.Data.Entity.Infrastructure.DbUpdateException if your update command fails, and it wraps a System.Data.UpdateException that finally wraps a System.Data.SqlClient.SqlException. It is also important to make a note that the inner-inner exception can be something other than a SqlException depending on the Entity Framework provider you are using.

If you unwrap these, you can get down to the raw SqlError objects that give you the specific details about problems with your update.

try 
{
    db.SaveChanges();
}
catch (DbUpdateException ex) 
{
    UpdateException updateException = (UpdateException)ex.InnerException;
    SqlException sqlException = (SqlException)updateException.InnerException;

    foreach (SqlError error in sqlException.Errors)
    {
        // TODO: Do something with your errors
    }
}

You can also gain a lot of power and control by also catching System.Data.Entity.Validation.DbEntityValidationException which will show you any validation errors that occurred during the call to SaveChanges. The default behavior is to validate changes on save. You can also pre-validate changes by calling DbContext.GetValidationErrors().

4

1 に答える 1

1

You passed your parameters wrong

ajaxeo("includes/php/ajax/changeProvider.php?oldID="+ID, "post", {"newVal": newValue});

should be

ajaxeo("includes/php/ajax/changeProvider.php?oldID="+ID, {"newVal": newValue}, "post");

The error is probably jQuery trying to make sure the method is in uppercase

于 2013-01-05T05:40:58.530 に答える