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.
app.factory('Greeter', ['$resource',function($resource){
  return $resource(
    'http://123.com/processor.php?'+'myvar=1066',
    {callback: 'JSON_CALLBACK'},
    {
      query: {method:'GET',isArray:true}
    });
}]);

I tried to pass a simple static variable into a php file to get call back value yet, its seem not pass correctly with the way I use above. Since the chrome inspector shows that

Query String Parametersview parsed
callback=JSON_CALLBACK

I wonder what is the right way to do it?

Thank You

share|improve this question
    
Are you trying to reinvent JSONP docs.angularjs.org/api/ng/service/$http#jsonp –  Krzysztof Safjanowski 16 hours ago

1 Answer 1

up vote 1 down vote accepted

Try this

app.factory('Greeter', ['$resource',function($resource){
  return $resource(
    'http://123.com/processor.php',
    {

          myvar: 1066,
          callback: 'JSON_CALLBACK'
    },
    {
      query: {method:'GET',isArray:true}
    });
}]);

Now you should get

http://123.com/processor.php?myvar=1066&callback=JSON_CALLBACK

after doing the following

Greeter.query()

or

http://123.com/processor.php?myvar=1066&callback=JSON_CALLBACK&myvar2=77777

by doing this

Greeter.query({myvar2: 77777});
share|improve this answer
    
Thanks! Worked well : D –  Chen 16 hours ago

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.