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 8237071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:20:54+00:00 2026-06-07T19:20:54+00:00

I am passing a variable into a URL, which then calls an API filtered

  • 0

I am passing a variable into a URL, which then calls an API filtered by the variable passed. However, I can’t seem to get the JSON to load, and returns an Invalid Error in Console of Firebug in JS. Thoughts?

$("a").click(function() {
    var apiurl = "http://api.example.com" + $(this).text() + "&limit=500" + "?callback=?";

    $.ajax({
        url: apiurl,
        success: function(json) {alert(json.data.results);},
        error: function() { alert("error"); },
        dataType: "json",
        contentType: "application/json;charset=utf-8",
    });
});

This is the error:
invalid label
error source line:
[Break On This Error]
{“code”:200,”status”:”Ok”,”data”:{“offset”:0,”limit”:500,”total”:17,”target”:”ch…

  • 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-06-07T19:20:56+00:00Added an answer on June 7, 2026 at 7:20 pm

    Remove: contentType: "application/json;charset=utf-8" from your request. Also you could use the $.getJSON() method which is a shorthand for what you have written. And don’t forget to return false from your click handler otherwise your call might never have time to execute before the browser redirects away following the href of the anchor that’s being clicked. Another thin go to notice is that you should use '&callback=?' instead of '?callback=?' in the url because apparently you already have the limit query string parameter so you are just adding another one. I suppose in this case that $(this).text() contains somewhere the ? which indicates the start of the query string:

    $('a').click(function() {
        var apiurl = 'http://api.example.com' + $(this).text() + '&limit=500' + '&callback=?';
        $.getJSON(apiurl, function(json) {
            alert(json.data.results);
        });
        return false;
    });
    

    Also I hope you realize that callback=? means JSONP that the API that you are trying to invoke must support. Otherwise your call will always be failing because you are violating the same origin policy restriction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using variable passing through a URL (ie .derp.html?name=derp?lname=herp) to a popup (which uses
For some unknown reason I'm running into a problem when passing a variable to
I have done urlencode of the variable before passing to the URL http://example.com/Restaurants?alias=F%26B But
I have a problem passing a variable through into a jquery function: function showImage(type,
I have a variable that contains JSON I need to pass into a template.
strtok function uses a static variable for parsing the string into tokens. So this
My Jquery date selector is passing my date variable in the format 22+Mar+2012 but
I am passing value of text-area in a.cfm in variable of GetXmlHttpObject to b.cfm
I often get strange resulst when passing int variables to tasks such as in
I have this code below. As you can see I am passing two variables

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.