Angularjs $ http无效

时间:2017-05-14 00:47:44

标签: angularjs rest

我正在尝试从angularjs访问REST Web服务。我无法成功调用它。

AngularJs代码

var singleOrderUrl = "/singleOrder/retrieve";
function getSingleOrderDetails(userName,singleOrderUrl,$http,$q) {
        var fd = new FormData();
        var deffered = $q.defer();
        fd.append('USERNAME', 'test123');
        //fd.append();
        //fd.append();
        console.log("inside service"+userName+"singleOrderUrl:::"+singleOrderUrl);
        return $http.get(singleOrderUrl, fd, {
            withCredentials : false,
            transformRequest : angular.identity,
            headers : {
                'Content-Type' : undefined,
            }

        }).success(function(response) {
            console.log(response);              
            responseData = response.data.toString();;               
            deffered.resolve(response);             
            return responseData;
        }).error(function(error) {
            alert("error");
            deffered.reject(error);
            return "failed";
        });
        };

休息服务代码

@RestController public class SingleOrderHistoryController {

private static final Logger logger = LoggerFactory.getLogger(SingleOrderHistoryController.class.getName()); 

@RequestMapping(value = "/singleOrder/retrieve", method=RequestMethod.GET, produces="application/json")
public List<SingleHistoryRecord> getSingleOrderDetails(@RequestParam(value = Constants.USER_NAME, required = true) String userName, HttpServletRequest request,HttpServletResponse response) throws Exception {

    logger.debug("inside SingleOrderHistoryController ");   
    List<SingleHistoryRecord> singleOrderHistoryList = new ArrayList<SingleHistoryRecord>();        
    SingleHistoryRecord record1 = new SingleHistoryRecord();
    SingleHistoryRecord record2 = new SingleHistoryRecord();

    record1.setClientIdentifier(userName);
    record1.setSubmitDate("01/05/2017");
    record1.setStatus("Complete");
    record1.setReferenceID("1234555");
    record1.setOrderID("test123");
    record2.setClientIdentifier(userName);
    record2.setSubmitDate("01/05/2017");
    record2.setStatus("Complete");
    record2.setReferenceID("1234555");
    record2.setOrderID("test123");      
    singleOrderHistoryList.add(record1);
    singleOrderHistoryList.add(record2);

    return singleOrderHistoryList;
}

任何人都可以告诉我这里做错了什么,它是获取页面的源代码而不是获取列表。

0 个答案:

没有答案