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

  • Home
  • SEARCH
  • 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 5846027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:31:08+00:00 2026-05-22T12:31:08+00:00

I searched for a related topic in jQuery, but I didn’t see any method

  • 0

I searched for a related topic in jQuery, but I didn’t see any method to solve my problem.

$(document).ready(function(){
    $("#inputForm").submit(function(event){
        $(":text").each(function() {
            var inputText = $(this).val();
            var userList = [];
            var weblink = 'http://test.com';

            // problem is from here.
            $.getJSON(weblink, function(data){
                alert(weblink); // this statement doesn't show up
                $.each(data, function(entryIndex, entry){
                    userList.push(entry['from_user']);
                });
            });
            alert(userList);
        });
     });
});

There are 3 problems here:

  1. Why doesn’t the first alert(‘weblink’) doesn’t show up?
  2. Why this code can’t get the json data from website?
  3. The goal of this code is to get the from_user tag from json file and store into userList array.

The variables in "$.each(data, function(entryIndex, entry){" statement, the function have two input parameters one is entryIndex and other is entry. I am wondering what these parameters are for and how to use them?.

Can anyone help me solve this problem. I have been stock in here for one day.
Thank you very much.

  • 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-22T12:31:08+00:00Added an answer on May 22, 2026 at 12:31 pm

    A couple of issues there:

    1. getJSON does an ajax request. Ajax requests are subject to the Same Origin Policy. Unless your page is loaded from http://test.com (or a couple of other caveats), it won’t work. You’re probably looking for JSON-P (which jQuery also supports), provided the server supports it.

    2. getJSON, like all ajax requests, is asynchronous by default, so your second alert (with the user list) will happen before the request completes. Although you can make ajax requests synchronous, it’s a very bad idea (locks up the UI of most browsers during the request). Instead, just use the user list after you’ve received it in the callback, rather than trying to use it in the function calling getJSON.

    Edit: You’ve said below that you’re trying to use the Twitter search API. That API does support JSON-P, so if you use JSON-P to do your request, it should work. e.g.:

    $(document).ready(function(){
        $("#inputForm").submit(function(event){
            $(":text").each(function() {
                var inputText = $(this).val();
                var userList = [];
                var weblink = 'http://search.twitter.com/search.json?q=&ands=google';
    
                // problem is from here.
                $.ajax({
                    url:        weblink,
                    dataType:   "jsonp", // <== JSON-P request
                    success:    function(data){
                        alert(weblink); // this statement doesn't show up
                        $.each(data.result, function(entryIndex, entry){ // <=== Note, `data.results`, not just `data`
                            userList.push(entry['from_user']); // <=== Or `entry.from_user` would also work (although `entry['from_user']` is just fine)
                        });
                        alert(userList); // <== Note I've moved this (see #2 above)
                    }
                });
            });
         });
    });
    

    …but surely you don’t want to do that for each text field in the form?

    Here’s a live example but without a form (and only doing one request, not a request for each field).

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

Sidebar

Related Questions

I have searched for related topic, but still can't solve the problem... use threads;
I searched ExtJS related questions and didn't found any reference, but if I missed
I have seen many related questions but didn't find any answer. I have successfully
I have searched here, but haven't found any question related to this. I got
Searched a lot about this problem but never found a answer, that solved it.
I've searched through related questions but can't find what I need. I have a
Sorry for asking this question, but I searched all Java-related questions, but I got
I searched for a long time, but I don't manage to retrieve two related
I searched SO and saw a few questions posted on the topic, but I
I have searched through the related mod_rewrite qustions but I can't anything specific enough

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.