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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:54:24+00:00 2026-06-09T09:54:24+00:00

my jquery looks like this: $(‘#id_start_date_list’).change( function get_time() { var value = $(this).attr(‘value’); alert(value);

  • 0

my jquery looks like this:

$('#id_start_date_list').change(
        function get_time()
        {
            var value = $(this).attr('value');
            alert(value);
            var request = $.ajax({
                url: "/getTime/",
                type: "GET",
                data: {start_date : value},         
                dataType: "json",
                success: function(data) {               
                //Popluate combo here by unpacking the json
        }
        });

        });

my view.py looks like this:

def getTime(request):
    if request.method == "GET":
        date_val =  request.GET.get('start_date')                        
        format = '%Y-%m-%d' 
        sd = datetime.datetime.strptime(date_val, format)
        sql_qw = MeasurementTest.objects.filter(start_date = sd)        
        results = [{'start_time': str(date.start_time), 'id_start_time':date.start_time} for date in sql_qw]
        print results                   
        *****json_serializer = serializers.get_serializer("json")()
        response_var=  json_serializer.serialize(results, ensure_ascii=False, indent=2, use_natural_keys=True)*****

    return HttpResponse(response_var, mimetype="application/json")

my html page looks like this:

html>
<head>
    <title>date Comparison</title>

<script src="http://code.jquery.com/jquery-latest.js"></script>    
</head>
<body>   
    {% if form.errors %}
        <p style="color: red;">
            Please correct the error{{ form.errors|pluralize }} below.
        </p>
    {% endif %}
    <form action="/example/" method="post" align= "center">{% csrf_token %}
         <table align = "center">
         <tr>
            <th><label for="start_date_list">Date 1:</label></th>
            <th>        {{ form.start_date_list }}          </th>               
        </tr>                  
        <tr>

        <th><label for="start_time_list">time:</label></th>
        <th><select name="start_time_list" id="start_time_list"></th>
            <option></option>           
        </select>
        <th></th>

        <div id = "log"></div>
        </tr>

        <tr align = "center"><th><input type="submit" value="Submit"></th></tr> 
         </table>         
    </form>
</body>
</html>

As you can see i am getting the value from the select box and i am performing operations on the database and retreiving values and storing it in the json object.

There are two parts that i am totally blind.
First is the json object, where i am not sure whether the results are getting stored in the response_var object.
The second is that, i am not sure how to get values from a json object onto the new list of “start_time_list”

In detail: have i have done anything wrong in the json object initialisation. I have tried to print the respose_var, but it seems not to be printed on the console. Am i using the right syntax? and can someone tell me how to view the values stored in the json object in the view.py

In the similar way, how do i perform operations on the jquery side, to extract values from a json object and how to assign the values of a json object onto a list box by means of sample code and possible solutions.

  • 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-09T09:54:26+00:00Added an answer on June 9, 2026 at 9:54 am

    To convert the results to json, use simplejson:

    from django.utils import simplejson
    def getTime(request):
    if request.method == "GET":
        date_val =  request.GET.get('start_date')                        
        format = '%Y-%m-%d' 
        sd = datetime.datetime.strptime(date_val, format)
        sql_qw = MeasurementTest.objects.filter(start_date = sd)        
        results = [{'start_time': str(date.start_time), 'id_start_time':date.start_time} for date in sql_qw]
        print results
        response_var = simplejson.dumps(results)
    
    return HttpResponse(response_var, mimetype="application/json")
    

    To access the json object in your javascript, take a look at your ajax request. The success callback is being passed a parameter, data in this case. That is the variable containing the server response. So, to access the first element of the resultant array (for instance), you could:

    var request = $.ajax({
      url: "/getTime/",
      type: "GET",
      data: {start_date : value},         
      dataType: "json",
      success: function(data) {               
        //Popluate combo here by unpacking the json
        data[0];  // This is the first element of the array sent by the server
      }
    });
    

    Lastly, to modify the html, jQuery provides plenty of methods, such as html or append. It’s worth taking a look at the doc. So if you want to build a collection of options for a select tag, you should iterate over the result set using the javascript for loop, jQuery each method or similar, construct the options (this can be accomplished either concatenating strings or creating DOM elements, which I think is the best solution, as it performs better) and insert them in the html with one of the methods previously mentioned.

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

Sidebar

Related Questions

I have some jquery that looks like this, $('.career_select .selectitems').click(function(){ var selectedCareer = $(this).attr('title');
I am making an ajax request using JQuery that looks like this: var data
My jquery looks like this var formContent =action=view&msgid=+id; $.getJSON(myserv.php,formContent, function(json){ $.each( json, function(k, v){`
jquery looks like this $.post('JSP/processForm.jsp', $(#Form).serialize(), function(data){ //I want to iterate through every line
I came across a piece of code which looks like this: jQuery(function($) { $('#saySomething').click(function()
I've built a jQuery selector for a function which looks like this: $('html').not('.table-main tr[selected]').mousedown(
I'm using Spring MVC and jquery autocomplete, my spring controller looks like this @RequestMapping(value
I have a problem with a jquery function. My HTML looks like this, I
I have my own edit in place function for jquery which looks like this
Here's an interesting problem: I have some jQuery that looks like this: $(document).ready(function() {

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.