如何在执行 Easy API 时将参数值传递给架构名称?

How To Pass paramerter value to schema name while executing Easy API?

我已经创建了 azure Easy API.I 可以通过调用 API 客户端传递参数值 method.But 我的问题是无法在 API.am 中获取模式名称得到意外连接 error.If 输入手动模式名称我得到结果。

 IN my controller

  $scope.saveuserdet = function (user) {
        $scope.LicenceId = user.LicenceId;
        $scope.username = user.username;
        $scope.name = user.name;
       
        var adduserclient = new WindowsAzure.MobileServiceClient('http//xxxxxxx');
        adduserclient.invokeApi('APIname', {
            body: null,
            method: "post",
            parameters: {
                schemaname :'myschemaname',
                license: $scope.LicenceId,
                uname: $scope.username
               
            }
        }).done(function (results) {
             var message = results.result.count + " item(s) marked as complete.";
          
        }, function (error) {
            $scope.showmessage = " Details are not Saved.Try Again";
        });
    };

module.exports = {
    //"get": function (req, res, next) {
    //}
  "post": function (req, res, next) {
         var query = {
         // sql: 'EXEC **@schemaname.<Storedprocedurename>** @license,@uname ',

             sql: 'EXEC **"'+ Myschema Name +'".<Storedprocedurename>** @license,@uname ',
             parameters: [
                 { name: 'schemaname', value: req.query.schemaname },
                 { name: 'license', value: req.query.license },
                 { name: 'uname', value: req.query.uname }]               
                };

         req.azureMobile.data.execute(query).then(function (results) {
             res.json(results);
         });
     }   
  
};

我用你的关键代码片段在我这边进行了测试。它工作正常。如果您使用 JavaScript Client Library for Azure Mobile Apps and test your application via a web server (test your application via visit Http://localhost:<port> on a browser), it may caused by the CORS issue. You can set your local origin into the CORS section of your mobile app manage protal on Azure portal (https://ms.portal.azure.com).

否则,您可以按浏览器的F12,如果您运行您的应用程序出现任何错误消息,请设置我。

顺便说一句,由于您使用的是POST方法,我建议您通过body参数传递数据。例如,

client.invokeApi('APIname', {
        method: "post",
        body: {
            schemaname :'myschemaname',
            license: $scope.LicenceId,
            uname: $scope.username

        }
    })

并且在您的 Easy APIs 脚本中,您可以通过 res.body 获取数据。