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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:59:30+00:00 2026-05-20T15:59:30+00:00

This seems like a simple problem but I have a coder’s mental block: The

  • 0

This seems like a simple problem but I have a coder’s mental block:

The concept:

I type a URL, i.e – http://www.mysite.com/getStuff?name=Jerry&occupation=Engineer&Id=12345

and instead of getting back a webpage or something I want to get back a json object so that I can parse on a different page.

The catch:

I can certainly accomplish this by calling a MVC controller with those parameters and returning a json object. However, Let’s say I need to create this json object inside a js file that takes those parameters’ values from the URL and I get my json back as the result.

The questions

Can I pass parameters to a js file and return a json object? Or
Can I call a js file from a controller and pass it these parameters to and retrieve a json object?
Do I even need to call a controller via a URL, or can I just call a js file giving it parameters from a URL and then returning the json?

What is the proper/best way of handling this scenario, with MVC, js, jquery…anything??

Thanks a lot guys!

  • 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-20T15:59:30+00:00Added an answer on May 20, 2026 at 3:59 pm

    Use jquery to parse the URL by inserting this into a <script> tag before creating the json object. from link from LekisS

    $.extend({
      getUrlVars: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++)
        {
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
      },
      getUrlVar: function(name){
        return $.getUrlVars()[name];
      }
    });
    
    // Get object of URL parameters
    var allVars = $.getUrlVars();
    
    // Getting URL var by its nam
    var byName = $.getUrlVar('name');
    

    In a separate script tag create your json object. You will need to include the Json2.js plugin to convert objects to JSON. So include this script also before the JSON object creation.

    Once you have the appropriate scripts and variables you can create a json object using those parameters as needed by calling them as shown at the bottom of the example using jquery. You can also look up which JSON conversion (i.e, to string or object) you want from the Json2.js script file.

    Now we have everything inside a bunch of scripts but where do we get json object through URL calling?

    So the answer is simple:

    Create a simple html page with these scripts where the last script finally creates and returns the json. Upload to server and use URL parameters like

    www.mysite.com/getStuff?para1=value&para2=value2 to get the json object.

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

Sidebar

Related Questions

This seems like a fairly simple problem to me but I have been having
I am learning LINQ and this seems like a fairly simple problem. I have
This seems like a really, really simple problem, but I can't figure it out.
This seems like a simple problem, but it is not intuitive to me. Say
This seems like a very simple and a very common problem. The simplest example
This seems like a simple question, but I can't find it with the Stack
This seems like a pretty softball question, but I always have a hard time
This seems like such a trivial problem, but I can't seem to pin how
I have what seems like a simple problem with some data in Excel. I
This sure seems like a simple error to fix. However, I somehow can't figure

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.