views:

39

answers:

2

Hi i am doing an exercise where I am trying to scrape content of nytimes website using javascript/ajax.

In order to send cross domain ajax request I am using a proxy server that returns me jsonp response with nytimes website content.

But since that html content has some charaters (single quotes) which throws "Illegal Character" error.

<script type="text/javascript" src="http://json-proxy.jgate.de/?callback=callback&amp;url=http%3A%2F%2Fwww.nytimes.com%2F"&gt;&lt;/script&gt;
<script>
function callback(obj) {
 alert(obj);
}
</script>

What could be a possible solution to this error? And what are other alternatives to solve this?

Thanks

(p.s. This question was asked to one my friends in his interview)

Update: Here is yahoo pipes link for the same. http://pipes.yahoo.com/pipes/pipe.run?_id=748e37c218ed0747d0b868ae8eafefa6&amp;_render=json

A: 

You have to escape the characters on the server.

callback('<!DOCTYPE html PUBLIC \"-//W...etc.') // notice the \"-//W

Instead of:

callback('<!DOCTYPE html PUBLIC "-//W...etc.') // which will eventually create an error

Escape all the special characters like /, \, ", ' to \/, \ ...

digitalFresh
I don't have access to that proxy server. I found that server online.
priyank
digitalFresh
A: 

Yahoo pipes fixed that issue.

priyank