0

I am solving a challenge where I have to click on a link "http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345" get the next nothing number from that page, and insert it at the end of the query string, probably, until there are no more "nothings" left and I have solved it.

I have tried making an Ajax request and getting the data of the next number to use in my next query stting, however oddly I get a syntax error. When I click on the error though, the data I am looking for is shown in the error "and the next nothing is 44827." Here is my code

$(document).ready(function(){
$.getJSON("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=12345&callback=?",

            function(data){
                console.log(data);
            }
        )
})

How can I do this without getting an error so I can repeatedly get the next "nothing"? And why am I getting a syntax error?

If this is the wrong way to go about solving this, I would appreciate any direction on the correct way to approach this.

Thank.

chhameed
  • 4,406
  • 4
  • 26
  • 44
  • show up the full error message ... ? – chhameed Jan 01 '17 at 08:32
  • linkedlist.php?nothing=12345&callback=jQuery3110322…_1483259612759&_=1483259612760:1 Uncaught SyntaxError: Unexpected identifier – n00bi3_stack Jan 01 '17 at 08:34
  • Is the receiving result is in json ? – chhameed Jan 01 '17 at 08:37
  • Once I hit the link it opens a separate tab in the console and it's just displayed in text : and the next nothing is 44827 – n00bi3_stack Jan 01 '17 at 08:38
  • You can work with jsonp - https://learn.jquery.com/ajax/working-with-jsonp/ – Kinnza Jan 01 '17 at 08:38
  • Also when you set a callback you need to have an actual function for it to call. So if you add callback=abc, you need a global function abc that handles the callback. the link i posted before shows a better example on how to handle this (jquery will handle it for you) – Kinnza Jan 01 '17 at 08:40
  • $.getJSON must receive results in json... if you don't know more about json then you can use simple ajax call ... http://www.w3schools.com/jquery/ajax_ajax.asp – chhameed Jan 01 '17 at 08:41
  • @mplungjan tried it with Ajax in that exact form, it returns the same error. First it gives CORS error then I add the dataType:jsonP and it gives same error. – n00bi3_stack Jan 01 '17 at 08:44
  • There is no JSON/JSONP support at the URL you give. If there is no CORS support, you need to write a server process - I assume Python challenge means for you to write server side python? http://stackoverflow.com/questions/2667509/curl-alternative-in-python -> http://docs.python-requests.org/en/latest/index.html – mplungjan Jan 01 '17 at 08:48

1 Answers1

1

$.getJSON Load JSON-encoded data from the server using a GET HTTP request.

you can use this code to work without json

 $.ajax({
      method: "GET",
      url: "http://www.pythonchallenge.com/pc/def/linkedlist.php",
      data: { nothing: "12345"}
    })
      .done(function( msg ) {
        console.log(data);
      });

Helping link for CORS support Cross Domain Details

Community
  • 1
  • 1
chhameed
  • 4,406
  • 4
  • 26
  • 44