0

I have a situation where I need to get data from an HTML file existing in another server. It will contain simply plain text content and nothing else. I don't have access to change anything there nor I can get any structured html. What I have is only text content stored in an HTML which is hosted in http://host1.demoserver.com.

Now, from my application which is hosted in http://host2.demoserver.com, I need to get the content through an ajax call. Problem is without implementing CORS. So, upto to my knowledge level I have an option JSONP. But, when I make ajax call with JSONP, I can see the response in Firebug, but it starts throwing javascript exception. There reason that comes into my mind(may be I am not correct) is that, since the content comes as callback parameter it contains undefined variables.

HTML file: copyright-info.html

This is a simple copyright info which needs to be rendered.

And, if we make a call with ajax call:

$.ajax({
    url: "http://host1.server.com/static/copyright-info.html?callback=?",
    method: "GET",
    dataType: "jsonp",
    jsonpCallback: "callback",
    callback: function(result) {
         //code to excute after success
    }
});

Then, response would be like:

callback(This is a simple copyright info which needs to be rendered.)

And, as parameter is not in double quotes its not recognizing it and throwing exception.

2nd, this whole thing was working without JSONP, when it was in localhost. And, I guess, http://host1.demoserver.com will be same localhost as it is for http://host2.demoserver.com. But, when it is deployed in server its failing.

Can anyone suggest what's wrong here? Or, any other way for implementing this.

Thanks in advance.

Ashmah
  • 842
  • 2
  • 8
  • 17
  • [maybe this will help](http://stackoverflow.com/questions/5463256/basic-how-to-for-cross-domain-jsonp) – Pete Jan 27 '15 at 12:05
  • As you have identified, the problem is that the response is not correctly expressed as JSONP. In order to fix that, you need to change the server side code, which you haven't shared with us. – Quentin Jan 27 '15 at 12:06
  • @Quentin, there is no server side code. I need to get the html content only. – Ashmah Jan 27 '15 at 12:30
  • @Pete, thanks! but its only saying that JSONP can not retrieve any form of data but well formatted JSON data. Is there any other way to solve for my problem.... – Ashmah Jan 27 '15 at 12:37
  • @Ashmah — As usual. There are two ways to get data from a different server. (1) co-operation (2) proxy – Quentin Jan 27 '15 at 12:40

0 Answers0