织梦CMS - 轻松建站从此开始!

沙龙国际-沙龙365国际_沙龙国际网上娱乐

当前位置: 主页 > www.salon365.com >

(www.salon365.com) 为什么jQuery可以正常请求,angula

时间:2017-07-17 18:50来源:未知 作者:admin 点击:
报 XMLHttpRequest cannot load http://example.com/v1/recharge. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response. recharge.createRecharge = function ( operatorId, operatorN

报 XMLHttpRequest cannot load http://example.com/v1/recharge. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

   recharge.createRecharge = function (
          operatorId, operatorName, amount, extraAmount, userId, userName) {
          var deferred = $q.defer();
          var data = {
            operator: {
              user_id: operatorId,
              user_name: operatorName
            },
            amount: amount,
            recharge_amount: amount   extraAmount,
            currency: 'SGD',
            user: {
              user_id: userId,
              user_name: userName
            }
          };

          data = angular.toJson(data);
          if (data) {
            $http({
              method: 'POST',
              url: 'example.com/v1/recharge',
              headers: {
                'Content-Type': 'application/json'
              },
              data: data
            })
              .success(function (d, status) {
                  deferred.resolve(d, status);
                }
              ).error(function (err, status) {
              console.log(err);
            });
          }

          return deferred.promise;
        };
        

下面这个却可以,

 var data = {
          'operator': {'user_id': '4320-9962-1b83f8fc4264', 'user_name': '乱石铺街'},
          'amount': 1,
          'recharge_amount': 2,
          'currency': 'SGD',
          'user': {'user_id': '4b92-ad75-506590099de5', 'user_name': 'ssdss'}
        };
        $.ajax({
          url: 'example.com/v1/recharge',
          method: 'POST',
          dataType: 'json',
          headers:{'Content-Type': 'application/json'},
          data: JSON.stringify(data),
          success: function (data) {
            alert(JSON.stringify(data));
          }
        });           

这个问题已被关闭,原因:问题已解决 - 问题已解决,且对他人无借鉴意义

织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片
栏目列表
推荐内容