你好我有一個角JS控制器這樣製造AJAX調用在角JS填充範圍數據
function InstantSearchController($scope){
$scope.items = [
{
url: 'http://tutorialzine.com/2013/04/services-chooser-backbone-js/',
title: 'Your First Backbone.js App – Service Chooser',
image: 'http://cdn.tutorialzine.com/wp-content/uploads/2013/04/service_chooser_form-100x100.jpg'
}
];
}
和我有一個AJAX調用
function getListOfJsonObjects(){
$.ajax({
url:"http://"+window.location.host+"/getListOfJsonObjects",
type: "GET",
beforeSend: function (request)
{
request.setRequestHeader("JSESSIONID", $.cookie("JSESSIONID"));
},
dataType: 'jsonp',
data: {
foreignKeyType:"OrgChartJSon",
},
success:
function(dataFromServer){
var parsedJSON = jQuery.parseJSON(JSON.stringify(dataFromServer));
},
error:
function(xhr, status, error){
alert("Failed");
}
});
}
我怎樣才能使一個$ http.jsonp調用,以便將響應數據放入作用域項目中。 請幫我試用var responsePromise = $http.jsonp(url, {params : {foreignKeyType:"DecisionTreeJSon"} });
甚至認爲響應狀態是200它始終進入失敗方法。
角碼:
<div ng-app="instantSearch" ng-controller="InstantSearchController">
<div class="bar">
<!-- Create a binding between the searchString model and the text field -->
<input type="text" ng-model="searchString" placeholder="Enter your search terms" />
</div>
<ul>
<!-- Render a li element for every entry in the items array. Notice
the custom search filter "searchFor". It takes the value of the
searchString model as an argument.
-->
<li ng-repeat="i in items | searchFor:searchString">
<a href="{{i.url}}"><img ng-src="{{i.image}}" /></a>
<p>{{i.title}}</p>
</li>
</ul>
如果您發佈了完整的Angular代碼而不是jQuery,將會很有幫助。 – MBielski