0

I'm obtaining data from an API and its JSON is stored on a separate file.

The URL for this file looks like this:

http://events.com/rsvp.php?id=1234

The JSON on the above page looks like this:

{
  rsvp: true
}

The id query string differs for each contact, so id 1234 might have rsvp: true but id 4321 might have rsvp: false.

What I'm trying to do is check the URL, get the value of the rsvp node and then, perform some action.

At the moment, with my request, I'm seeing the log error, unsure why?

<!-- this gets the id field -->
{% set contact_id = request.query_dict.id %}

{% set base_url = "http://events.com/rsvp.php?id=" %}
{% set url = base_url + contact_id %}

<script>

$(function() {

  $.ajax({
    url: "{{ url }}",
    method: "GET",
    dataType: 'json',
    success: function(result){
      console.log(result);
    },
    error:function() {
      console.log("Error")
    }
  });

});

</script>

1
  • Check the console to see a description of the exact issue. Commented Aug 11, 2020 at 10:35

1 Answer 1

2

Your JSON is invalid.

Property names in JSON must be strings, not identifiers.

{
  "rsvp": true
}

Generate your JSON with json_encode, not with whatever method you are currently using.

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

Comments

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.