1

This is my proxy.php file:

$url = urldecode($_GET['url']);
$url = 'http://' . str_replace('http://', '', $url); // Avoid accessing the file system
echo file_get_contents($url); // You should probably use cURL. The concept is the same though

and my reader.js:

$(document).ready(function () {

    var url = 'http://localhost/taboo.blue-world.pl/admin/proxy.php?url=' + encodeURIComponent('http://www.blue-world.pl')

    $.ajax({
        url      : url,
        type     : 'GET',
        dataType : 'json'
    }).done(function(data) {
        console.log(data.results.result[1].category); // Do whatever you want here
    });
});

But it doesnt print anything. Can you help me solve it? I am not quite good with this.

1
  • is your url returning proper JSON formatted string or an HTML? If HTML, dataType:json will interfere, as your php does not return JSON. Commented Jan 22, 2016 at 7:24

4 Answers 4

1

Currently your are trying to get JSON response. Change dataType to html.

dataType: 'html'
Sign up to request clarification or add additional context in comments.

Comments

1

It looks like you are trying to get an HTML response as JSON.

If the content is HTML you should turn you ajax call to:

$.ajax({
    url      : url,
    type     : 'GET',
    dataType : 'html'
}).done(function(data) {
    console.log(data); // data contains the html as a text
});

Comments

1

Use either dataType: 'html' in reader.js (to get HTML data)

OR

echo(json_encode(file_get_contents($url))); in proxy.php (for JSON data)

Comments

0

Try jQuery.parseJSON for json format

 $.ajax({
        url      : url,
        type     : 'GET',
        dataType : 'json'
    }).done(function(data) {
        var data = jQuery.parseJSON(data);
        console.log(data.results.result[1].category); // Do whatever you want here
    });
    });

Comments

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.