Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Hello i have a angular js controller like this

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'
    }
];

}

and i have a ajax call

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");
    }
});

}

how can i make a $http.jsonp call inorder to put response data into scope items. please help i tried with the call var responsePromise = $http.jsonp(url, {params : {foreignKeyType:"DecisionTreeJSon"} } ); even thought response status is 200 it always entered into failure method.

angular code:

<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>

share|improve this question
1  
It would be helpful if you posted your full Angular code instead of jQuery. –  MBielski Mar 25 at 14:54

1 Answer 1

Don't use jQuery at all in AngularJS projects.

You must use $http $resource services to query webservices.

Here is a plunker to show how to use $http to fill the scope, it is not jsonp but you should easily extends this example.

share|improve this answer
    
if i use $http i get XMLHttpRequest cannot load getListOfJsonObjects/?foreignKeyType=JSon. No 'Access-Control-Allow-Origin' header is present on the requested resource. error –  Ekata Mar 25 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.