0

So I'm trying to load a page with a URL as a GET variable. Unfortunately, I keep getting a 404 from apache. Using JQuery, my syntax for the request is the following:

$.ajax({
    type: "GET",
    url: "page.php&url="+theURL,
    dataType: "xml",
    success: function(xml){
        loadFeed(xml);
    }
});

and the php for page.php is as follows:

<?php

domain="localhost";

header('Content-type: application/xml');

referer=$_SERVER['HTTP_REFERER'];

if(!stripos($referer, $domain)){
    print("BAD REQUEST");
    return;
}

$handle = fopen($_GET['url'], "r");
if ($handle) {
    while (!feof($handle)) {
        $buffer = fgets($handle, 4096);
        echo $buffer;
    }
    fclose($handle);
}
?>

Not sure what i'm doing wrong here.

3
  • 2
    Your javascript can't find your PHP file, hence the 404 error. Commented Feb 7, 2014 at 0:48
  • 3
    Your PHP file is missing some $ on variables. It probably doesn't even compile. Commented Feb 7, 2014 at 0:50
  • Apart from @Ibu's answer, you probabaly also need to encode the url in javascript: stackoverflow.com/questions/332872/… Commented Feb 7, 2014 at 0:51

1 Answer 1

3

YOu have an error in your url:

$.ajax({
    type: "GET",
    url: "page.php&url="+theURL,  // Here
    dataType: "xml",
    success: function(xml){
        loadFeed(xml);
    }
});

should be:

$.ajax({
    ...
    url: "page.php?url="+theURL,  // Here
    ...
});

Note I used a question mark instead of ampersand. Also this might be a typo but you are missing the $ in front of variables

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

1 Comment

Thanks alot. Sometimes it just takes a second set of eyes.

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.