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

The Archive Base Latest Questions

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

via ajax, I want to post some data and if model successfully gets saved,

  • 0

via ajax, I want to post some data and if model successfully gets saved, returns answer as a JSON object.

Here is my jquery based ajax post:

var requestData = { 'ievent_id': type , 'channel_id': CHANNEL_ID , 'start_date': dateToStrConverter(start_date) , 'end_date': dateToStrConverter(end_date) };
$.ajax({
    type: "POST",
    url: "my-ajax-url/",
    data: requestData,
    dataType: "json",
    success: function(data){
        console.log( "ID:" + data.plan_id + " Error:" + data.error);
    },
    error: function(msg){
        alert( "Theres an error with the server." );
    }              
});

And my Django view that handles this ajax call to save iEventPlan objects and return response:

from django.utils import simplejson as json

def planner_save_view(request):
    if request.method == "POST" and request.is_ajax():
        root = json.loads(request.raw_post_data[0])

        ##data
        ievent = iEvent.objects.get(pk = root['ievent_id'])
        channel = Channel.objects.get(siservice = root['channel_id'])
        start_date = datetime.strptime(root['start_date'],'%d-%m-%Y %H:%M')
        end_date = datetime.strptime(root['end_date'],'%d-%m-%Y %H:%M')
        response_dict = {}
        try:
            plan = iEventPlan(red_button=ievent,channel=channel,start_date=start_date,end_date=end_date)
            plan.save()
            response_dict.update({'plan_id': plan.id})
        except:
            response_dict.update({'error': "theres a problem."})
        return HttpResponse(json.dumps(response_dict), mimetype="application/json")
    else:
        HttpResponse("Not authorized.")

This is the error I get:

JSONDecodeError at /my-ajax-url/

No JSON object could be decoded: line 1 column 0 (char 0)

What I am doing wrong? I will be grateful if you show me the proper way of handling ajax based django model savings and responses.

  • 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:33:47+00:00Added an answer on May 18, 2026 at 7:33 pm

    You’re sending POST data in the standard form encoding. The dataType attribute doesn’t specify type of data to send, but the one you expect to receive. If you really want to send JSON from your browser, you should do something like this:

      $.ajax({
        data: JSON.stringify(data),
        processData: false,
        contentType: 'application/json',
        // other options
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to post a form via ajax call also model will be passed
I've got a json encoded dataset that I retrieve via ajax. Some of the
The Setting: The program in question tries to post form data via an AJAX
I have an application in which most requests are submitted via AJAX, though some
I'm stumped. I'm using jquery and ajax to POST some fields from a form
I am using Jquery AJAX to post a form on my page. I want
I am working on a website which loads its data via AJAX. I also
This is pandastream's pandauploader . Except I want it to be sent via AJAX.
I have a form and I want the calculations to be done via ajax
I have an ajax call bound to a link via jQuery, and I want

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.