Mar 29, 2010

My code... looking for some help

I have posted my code and hoping to see if anyone notices where my error or errors are. The first bit of code is my php file.


$url = "http://api.fanfeedr.com/basic/all_scores?appid=735sdkx8cqvh8jbwyfzmr3x7"
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response_body = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if (intval($status) != 200) die("Error: $response_body");
var_dump(json_decode($response));
?>





This piece of code is my javascript. I am sorry I don't know how to post code like Adam did, where it was more organized. I used the blockquote which seemed to help the spacing.

function checkRival() {
fanfeedr();

}

function createRequest() {
try {
request = new XMLHttpRequest();
} catch (tryMS) {
try {
request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (otherMS) {
try {
request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (failed) {
request = null;
}
}
}
return request;
}



function fanfeedr() {
createRequest();

if (request == null) {
alert("Unable to create request");
return;
}
var url= "getFeedr.php";
request.open("GET", url, true);
request.onreadystatechange = displayFeedr;
request.send(null);
}
function displayFeedr() {
if (request.readyState == 4) {

if (request.status == 200) {
alert("here");
//var myObject = eval('(' + myJSONtext + ')');
detailDiv = document.getElementById("fanfeedr");
detailDiv.innerHTML = request.responseXML;

}
}
}




I think I need to fix how this is being displayed. I wrote in a previous blog comment that I was going to look at what Adam wrote and try and incorporate some of that. I am not sure that will work or not but is always worth a try. Does anyone else have any more suggestions for me?

3 comments:

  1. Steven, What exactly is the problem you are having? Are you getting a response from the server and if not is it returning an error to the page through the Javascript? On thing that sticks out to me is the responseXML. In all of my apps I used responseText not responseXML but I'll check into that tomorrow and see what I can find out. Also I'll see what I can figure out with the code? Are you getting the alert that you have set up in the displayFeedr function? If not chances are that the problem is with the PHP. I'll let you know tomorrow.

    ReplyDelete
  2. I can view the JSON by putting the URL in the web browser, my javascript won't display it on my web page. I am getting the alert in the displayFeedr function.

    ReplyDelete
  3. Wish I could help, I will be posting my code later today. I did my code with XML not JSON though so hopefully you can compare if they arent that different.

    ReplyDelete