2

I have got this function:

 var current_url=window.location.href;
$.ajax({url:      'http://api.apps.com/html/'+appid,
      data:      {url:current_url},
      dataType: 'jsonp',
      timeout:  10000,
      jsonp: "set_url_target",
      success: function(data) { console.log(data); },
       error: function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); console.log(textStatus); }
      }).done(function() { 
          console.log("Message has been complete!!");
        });

What I want is to trigger this function on http://api.apps.com/html/ (Note it is a different domain).

function set_url_target(url){
    console.log("Url has been recieved: "+url);
}

So far the set_url_target isnt being triggered, and I get nothing being printed to the console, no error or nothing.. why?

2 Answers 2

2

if the external application isnt under your control I am afraid you cannot do much as you need to update the response that is sent by the server to the client side to use JSONP successfully..

thus you have two options: a) make the call on server side in your application and return it to the client b) alternatively to entirely make it client side you could use something like yahoo pipes or other services which transform the json response to valid jsonp response.

here is an example on how to do it using yahoo pipes: https://gist.github.com/316660

I am not sure about the license, do check upon them and if there are and associated API/Bandwidth costs. Let me know how it works out for you..

Sign up to request clarification or add additional context in comments.

1 Comment

So basically the solution is to use a proxy!?? I am trying to emulate html5 messaging with jsonp, but why doesnt it work? but what I am trying to do is do a client to client request.. so u say it is not possible..why?
0

Try this, note the jsonp and jsonpCallback attributes

    var current_url=window.location.href;
    $.ajax({url:      'http://api.apps.com/html/'+appid,
            data:      {url:current_url},
            dataType: 'jsonp',
            timeout:  10000,
            jsonp : false,
            jsonpCallback: "set_url_target",
       success: function(data) { console.log(data); },
       error: function(jqXHR, textStatus, errorThrown) { console.log(errorThrown); console.log(textStatus); }
  }).done(function() { 
      console.log("Message has been complete!!");
    });

For more info on this, AJAX

2 Comments

no didnt work. why is the jsonp false? , does it tell it not to return jsonp? set_url_target is on a different script on a different domain, not on mine.. I think you misunderstood the question. !?
jsonp is set to false to override the Callback name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.