0

Trying to retrieve the value of a input field in a external site's webpage. They wont change the headers. So been told to use Jsonp. Never used this. Anyone have any examples or can point me in the right direction?

Outline: External Site:

<input type="hidden" id="ImHiddenGetMe" value="Get Me If You Can">

Cannot use ajax/jquery as they wont change the headers to allow the cross domain.

  • possible duplicate of http://stackoverflow.com/questions/9922101/get-json-data-from-external-url-and-display-a-particular-value-by-injecting-it-i – mituw16 Apr 03 '14 at 14:27
  • "But source must be aware that you want it to call function passed as callback parameter to it." - It isn't. –  Apr 03 '14 at 14:33
  • Do you have access to the other server, i.e. can you configure it? – Stephan Kulla Apr 03 '14 at 14:40
  • Nope I requested they change the headers so I could just use jquery and ajax, they said no. I've built a C# application that just grabs the info and displays for the user who needs the info but apparently its not tidy and they want it embedded to our script. They suggested I use JSONP never used it, does it require the server to postback? –  Apr 03 '14 at 14:45

1 Answers1

0

For using JSONP the other server must provide an interface to it. For example: The other server must provide an URL like

http://other.com/getvalue?jsonp=callbackFunction

This URL must sent JavaScript code like

callbackFunction({ value: "Get Me If You Can" })

If the other server does not provide such an interface and do not provide the Access-Control-Allow-Origin Header necessary for Cross origin resource sharing you cannot load the other site via AJAX.

But you can always program a crawler which stores the value periodically on your server (where you can use it). Please respect the other server's robots.txt in this case.

Stephan Kulla
  • 4,739
  • 3
  • 26
  • 35