title: JSON parse error in ajax script using Django Rest framework
body: <p>I am using django rest framework.My views response is ok but when i submit my view using ajax it gives me an error json parse error.</p>
  <pre><code>Here is my views.py file:
  
  @api_view(['GET', 'POST'])
  @parser_classes([JSONParser])
  def signup(request, format=None):
      if request.method == 'POST':
          data = JSONParser().parse(request)
          username = data.get('username')
          first_name = data.get('first_name')
          last_name = data.get('last_name')
          email = data.get('email')
          password = data.get('password')
          gender = data.get('gender')
          birth_date = data.get('birth_date')
          serializer = UserSerializer(data=data)
          if serializer.is_valid():
              user = User.objects.create_user(username=username,first_name=first_name,last_name=last_name,email=email,gender=gender,birth_date=birth_date)
              user.set_password(password)
              user.save()
              data = {'result': 'success', 'message':'You have registered successfully now you can login'}
              return Response(data=data, status=201)
          elif not serializer.is_valid():
              data = { 'result': 'error', 'message':serializer.errors}
              return Response(data=data)
      if not request.user.id and request.method == 'GET':
          return render(request, 'sessionauthapp/signup.html')
  </code></pre>
  <p>My ajax js script:</p>
  <pre><code>var frm = $('#signupform');
  var token = '{{csrf_token}}';
  
  $('#signupform').on('submit', function(e) {
      e.preventDefault();
      $.ajax({
          headers: { &quot;X-CSRFToken&quot;: token },
          url: '/signup/',
          type: 'post',
          data: $(this).serialize(),
          dataType: &quot;json&quot;,
          contentType: &quot;application/json&quot;,
  
          success: function(data) {
              console.log(data);
  
            
  
          },
          error: function(data) {
  
          }
      });
      return false;
  });
  </code></pre>
  <p>My ajax script gives me an error like <code>json parse error</code> but my views response is ok.</p>