Jump to content

Sean_Tublewicz

New Members
  • Posts

    6
  • Joined

  • Last visited

Sean_Tublewicz's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hello Requinix. I think I'm getting closer. Now instead of the alert box I just get NULL to show up in the divContainer. here is proxy.php: <?php if (!isset($_GET['url'])) { die(); } $url=urldecode($_GET['url']); $url='http://' . str_replace('http://','',$url); echo file_get_contents($url); ?> and here is my HTML file: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <title>TEST PAGE</title> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> getJSON = function() { var resultDiv = $("#resultDivContainer"); resultDiv.html('Loading...'); var request = { version: "0.4", game: "XXXXXXXXX", platform: "XXXXXXXXX", userId: "XXXXXXXXX", password: "XXXXXXXXX", data: {} }; $('#sendInput').val(JSON.stringify(request)); resultDiv.html(console.log('Sending: ' + $('#sendForm').serialize())); $.ajax({ url: "proxy.php?url=XXXXXXXXX", type: "POST", data: $('#sendForm').serialize(), dataType: "json", success: function (result) { var resultString = JSON.stringify(result); console.log('Result: ' + resultString); resultDiv.html(resultString); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }; </script> </head> <body> <h1>Test Page</h1> <form id="sendForm" action="post"><input id="sendInput" type="hidden" name="json" value="empty" /></form> <div id="resultDivContainer"></div> <button type="button" onclick="getJSON()">JSON</button> </body> </html> As I said it appears to communicate with the servlet... and just enters null into the resultDivContainer and the browser javascript log says sending blah blah blah and result: null. Thanks for the help so far and hopefully with your help I can get this going.
  2. Does the browser log make you think I'm sending requests to myself? I am indeed trying to access a servlet sitting halfway around the world. I tried accessing the local HTML file using http://localhost:8888/test.html to see if it was on my end though it still did not work. I was wondering if just accessing the page using PHP would be easier.
  3. Would it be easier if I can just use PHP for the whole deal? That is fine by me. Unfortunately I can't find many examples that apply to my situation. Does anyone know of any or can you write up a basic one? I don't believe the server is setup to use cURL either. Thanks guys.
  4. Hello and thank you for the response requinix. I checked the javascript log and was presented with XMLHttpRequest cannot load XXXXXXXXXXXXx. The 'Access-Control-Allow-Origin' header has a value 'http://localhost:8888' that is not equal to the supplied origin. Origin 'http://localhost' is therefore not allowed access. My question is... Is this on my end or the servlet I'm trying to access?
  5. Make a variable on page load and set value to 1. Each time a new page is pulled in increment the value by 1 and call the link with the variable... Or are you looking for actual code?
  6. I'm sorry if this is in the wrong section. I'm working on coding a page that will pull data from a servlet that's already been coded. Right now I'm just trying to get it to pull and display any information. The developer who coded the servlet says it works on his server and I'd rather not badger him with questions. Any help you can provide would be greatly appreciated. So I am running Wampserver 2.5 a basic installation as I have not changed any settings and my HTML page is as follows: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <title>TEST PAGE</title> <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <script type="text/javascript"> getJSON = function() { var resultDiv = $("#resultDivContainer"); resultDiv.html('Loading...'); var request = { version: "0.4", game: "XXXXXXXXX", platform: "XXXXXXXXX", userId: "XXXXXXXXX", password: "XXXXXXXXX", data: {} }; $('#sendInput').val(JSON.stringify(request)); resultDiv.html(console.log('Sending: ' + $('#sendForm').serialize())); $.ajax({ url: "XXXXXXXXX", type: "POST", data: $('#sendForm').serialize(), dataType: "json", success: function (result) { var resultString = JSON.stringify(result); console.log('Result: ' + resultString); resultDiv.html(resultString); }, error: function (xhr, ajaxOptions, thrownError) { alert(xhr.status); alert(thrownError); } }); }; </script> </head> <body> <h1>Test Page</h1> <form id="sendForm" action="post"><input id="sendInput" type="hidden" name="json" value="empty" /></form> <div id="resultDivContainer"></div> <button type="button" onclick="getJSON()">JSON</button> </body> </html> This is supposed to display some JSON results from a tournament that is ongoing. When I click the JSON button it'll change the resultDivContainer to say "Loading..." and then it gives me a popup that says: "The page at localhost says: 0". Is it because I'm not on the same domain as the servlet? Thoughts? Please and thank you.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.