Js angular bug only on Safari

2019-09-22 01:30发布

问题:

I have the following code:

$http.post(constants.path+'address.php', {form}).then(function(data){
                console.log(data);
                console.log("success");
            });
        }

Only on Safari I get the following error:

'SyntaxError: Unexpected token '}'. Expected a ':' following the property name 'form'. 

Every other browser don't complain about this code. Any ideas ?

EDIT 1: The whole function is:

function enviaVaga(form){
    console.log(form);
    return $http.post(constants.path+'json.php', {form}).then(function(data){
        console.log(data);
        console.log("sucesso");
    });
}

This is a service function to send data to my backend

EDIT2: Just for future reference, removing the {} created the problem that my backend was expecting to receive a form object on $formData, to solve this I use {form: form}, that works well on Safari.

回答1:

You aren't passing anything valid for data. Safari is attempting to interpret {form} as a new object.

Other browsers may be more gracious, but just drop the { and }.

Actually, other browser might be interpreting {form} as object short notation which is not supported by safari. see: https://kangax.github.io/compat-table/es6/#object_literal_extensions