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 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 some data to a file via ajax when somebody clicks
I get some data from an PHP-Script via AJAX and want to have the
i want to download a file using ajax via post request using jQuery. here
I want to get, via ajax, a collection of data objects and parse them
I want to shrink the data that is sent back and forth via AJAX,
Im submitting Data to a php file via AJAX using POST. It worked fine
Say I have a default model which is posted via AJAX: var data =
From my view I am sending via $.ajax a JSON object to my controller
I need a web sites some data which I want to parse via jquery.
I want to send some data in json format to php and do some

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.