0

I am trying to set up a function that will filter through JSON array data being brought in from a different domain, but I am running into an error: "Uncaught SyntaxError: Unexpected token :"

This is how things are setup so far:

jQuery.noConflict();

(function($) {
    $(document).ready(function(){

        $.ajax({
            url: 'http://[website-name].org/json/North',
            context: this,
            dataType: "jsonp"
        }).done(function() {
            $.each(data, function(index) {
                alert(data[index].Name);
                alert(data[index].WaitTime);
            });
        });
    });
}(jQuery));

The url contains the JSON data setup in this exact format: {"Name":"Facility Name","WaitTime":"30 min"}

But it seems that the error is pointing to that exact setup. I'm not sure what I'm missing. I'm pretty new to using the jQuery.ajax function, so I may be missing something. The code never seems to make it to the .done part, and I think the JSON data is set up in the correct format (I could be wrong, though).

2
  • I believe you have to pass the response/data into the done method arguments. besides that I'm unsure why you're receiving that error. Commented Jul 22, 2015 at 18:25
  • you're missing your parameter in your done function, it needs to look like this .done(function(data) { Commented Jul 22, 2015 at 18:27

1 Answer 1

2

There are few things wrong in your code. And they are,

.done(function(data) {
   var responseData = JSON.parse(data); //Convert the response string to actual JSON data
   $.each(responseData, function(index) {
      alert(responseData[index].Name);
      alert(responseData[index].WaitTime);

      //Please add a debug point using your devtools and see what is returned as index and act upon that data.
   });
});

In your code it should throw an error cus your are passing a string into the each function.

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

2 Comments

This got rid of the error message but the alerts do not appear to work. I don't see any indication that the data is being retrieved other than the lack of an error now...
I've made a change in the answer I've given, but it would be good for your to add a debug point to your code and see the execution.

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.