Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3595418
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T19:50:57+00:00 2026-05-18T19:50:57+00:00

I am trying to make a call with this script, but am getting a

  • 0

I am trying to make a call with this script, but am getting a “Uncaught SyntaxError: Unexpected token :”

I can’t figure out where I’m going wrong, I don’t know if it’s something with my callback. I am sending a valid JSON packet so I don’t think that’s the issue. Anyway, here’s my html/jquery call:

<script>
function loadJSON(){
    $.getJSON("http://localhost:8000/api/0.1/tonight-mobile.json&callback=?", function(data){
            alert('hey');
             $('result').append(data);
             alert('hey 2'); 
         $.each(data, function(i, json){});

    });
    alert('hey 3');
}
</script>

With this corresponding function in my django view:

def tonight_mobile(request):

    callback = request.GET.get('callback', '')

    def with_rank(rank, place):
        return (rank > 0)

    place_data = dict(
        Places = [make_mobile_place_dict(request, p) for p in Place.objects.all()]
    )

    xml_bytes = json.dumps(place_data)
    return HttpResponse(xml_bytes, content_type='application/json; charset=utf-8')

Here is my request being logged by my server (so I know its at least getting that far with a OK status code):

"GET /api/0.1/tonight-mobile.json&callback=jsonp1293142434434 HTTP/1.1" 200 167

Displaying this error in my javascript console:

Uncaught SyntaxError: Unexpected token : tonight-mobile.json&callback=jsonp1293142434434:1

If you need to see my JSON format (if that is what’s causing this) please let me know and I can post it too.

Thank you in advance for your help!


UPDATE:

Here’s the response coming from my server:

{"Places": [{"url": "http://localhost:8000/api/0.1/places/1.plist", "image_url": "http://localhost:8000/static/place_logos/Tsonoqua_Mask.gif", "name": "Boo's Place"}]}
[23/Dec/2010 17:37:22] "GET /api/0.1/tonight-mobile.json&callback=jsonp1293147441552 HTTP/1.1" 200 167

UPDATE 2:

I’ve managed to get my callback working correctly! Here’s the code:

Client side:

<script>
function loadJSON(){
    $.getJSON("http://localhost:8000/api/0.1/tonight-mobile.json&callback=?", logIt(data));
}
function logIt(data){
    window.console && console.log(data);
    alert('yay!');
}
</script>

Server side:

def tonight_mobile(request):
    callback = request.GET.get('callback', 'logIt')

    def with_rank(rank, place):
        return (rank > 0)

    place_data = dict(
        Places = [make_mobile_place_dict(request, p) for p in Place.objects.all()]
    )

    xml_bytes = json.dumps(place_data)

    if callback:
        xml_bytes = '%s(%s)' % (callback, xml_bytes)
    print xml_bytes

    return HttpResponse(xml_bytes, content_type='application/javascript; charset=utf-8')

This returns the following response:

logIt({"Places": [{"url": "http://localhost:8000/api/0.1/places/1.plist", "image_url": "http://localhost:8000/static/place_logos/Tsonoqua_Mask.gif", "name": "Boo's Place"}]})

Is this how it should function? It seems I should be able to simplify the getJSON call… I just want to make sure I’ve done everything I need to correctly with my callback before I continue forward parsing the response and setting them to elements on the page.


UPDATE 3*

So, I’ve made quite some progress!! I’m using Jquery mobile, so ignore some of the following overdone css, its not related to the core issue.

I’m having a problem looping over the “Places” in my JSON packet. I am getting a response with multiple “Places”, but can’t seem to figure out how to iterate over them. My ‘i’ variable in my each loop is working correctly for the first element, and displaying its corresponding name & image.

My getJSON and callback method have evolved into this:

<script>
function loadJSON(){
    $.getJSON("http://localhost:8000/api/0.1/tonight-mobile.json&callback=?", callback(data));
}
function callback(data){
    $("#tonight-list").each(data.Places, function(i) {
        $(this).append("<li role='option' tabindex='" + data.Places[i] + "' class='ui-li-has-thumb ui-li ui-btn ui-btn-icon-right ui-corner-top ui-corner-bottom ui-controlgroup-last ui-btn-down-c ui-btn-up-c' data-theme='c'><div class='ui-btn-inner ui-corner-top ui-corner-bottom ui-controlgroup-last'><span class='ui-icon ui-icon-arrow-r'></span><div class='ui-btn-text'><img src=" + data.Places[i].image_url + " alt=" + data.Places[i].name + " class='ui-li-thumb ui-corner-tl ui-corner-bl'/><h1 class='list-title ui-li-heading' id='list-title'><a href='detail.html?id=slide' data-transition='slide' class='ui-link-inherit'>" + data.Places[i].name + "</a></h1><span class='ui-li-count ui-btn-up-c ui-btn-corner-all'>" + data.Places[i].events + " events</span></div></div></li>");
    });

}
</script>

Here’s my response:

callback({"Places": [{"url": "http://localhost:8000/api/0.1/places/3.plist", "image_url": "http://localhost:8000/static/place_logos/Bengals_1.png", "name": "Big 12", "events": 2}, {"url": "http://localhost:8000/api/0.1/places/2.plist", "image_url": "http://localhost:8000/static/place_logos/Makonde_Mask.gif", "name": "Harpo's", "events": 0}, {"url": "http://localhost:8000/api/0.1/places/1.plist", "image_url": "http://localhost:8000/static/place_logos/Quintons_1.png", "name": "Quinton's", "events": 1}]})

Am I confusing how the each function iterates over the JSON (which become) Javascript objects? I am pretty sure the each is my issue here, as I am only getting the FIRST element of the “Places” list. Can someone please help me out?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T19:50:58+00:00Added an answer on May 18, 2026 at 7:50 pm

    Yes to return jsonp you need to wrap the response in a function:

    def tonight_mobile(request):
    
        callback = request.GET.get('callback')
    
        def with_rank(rank, place):
            return (rank > 0)
    
        place_data = dict(
            Places = [make_mobile_place_dict(request, p) for p in Place.objects.all()]
        )
    
        xml_bytes = json.dumps(place_data)
        if callback:
            xml_bytes = '%s(%s)' % (callback, xml_bytes)
        return HttpResponse(xml_bytes, content_type='application/json; charset=utf-8')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make an ajax call to a php script. The php
I'm trying to make some custom Google maps info windows, but I'm getting the
I was trying to make weather based PHP script to show weather related data.But,I'm
im trying to make this box stay one one width at 150px but how
I have been trying for hours to make this work but I am not
I am trying to make a sort of license checking script, but as not
I'm trying to figure out the best way to do this in jquery. I'm
I am trying to make a call to api which returns json object {
I'm trying to make a call that might throw an exception due to server
I am trying to make a call to a Parent class method from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.