Issue with Greasemonkey script causing 400 error on POST request

I am currently working on a Django application that exposes an API with the following URL configuration:

url('^links/', linkhandler),

The link handler is a Django piston resource with a POST (Create function) outlined below:

 def create(self, request):

    try:

        link_obj  = Link.objects.get(link = request.POST['link'])
    print link_obj
        link_obj.rec_count = link_obj.rec_count + request.POST.get('rec_count', 1)
        link_obj.save()
        return link_obj
    except:
        try:

            query_obj = Query.objects.get(query_word = request.POST['query'])
    print query_obj
        except:
            query_obj = Query(query_word = request.POST['query'])

            query_obj.save()

        link_obj = Link(link = request.POST['link'], rec_count = request.POST.get('rec_count', 1), query = query_obj)
        link_obj.save()

        return link_obj

Everything seems to be functioning properly and I can successfully make POST requests using CURL. An example of a CURL request that works is shown below:

curl -d "query=hp&link=http://www.shopping.hp.com/&rec_count=1" http://localhost:8000/api/links/

However, when attempting this from a Greasemonkey script, it consistently returns a 400 error.

Below is the relevant Greasemonkey script:

 GM_xmlhttpRequest({
                method:"POST",
                url:"http://localhost:8000/api/links/",
                headers:{
                    "User-Agent":"Mozilla/5.0",
                    "Accept":"text/json",
                    "Content-Type" : "application/x-www-form-urlencoded" 
                },
                data: encodeURI("query="+GM_getValue('q', '')+"&link="+this.previousSibling.href+"&rec_count=1"), 
                onerror: function errorhand(){
                    alert("An error occurred!");
                }
            }); 

What could potentially be causing this issue?

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble getting my initial Vue.js code to function properly alongside basic HTML

I am in need of assistance with this code as it does not seem to be working properly. I am using an external js file named app.js for the Vue JS code in the index.html file. Here is the code from index.html: new vue({ el: '#app', data: { ...

What is the best way to ensure the submenu is visible on every menu when the cursor hovers over it

I am currently working on implementing a drop-down menu using react.js. I have been following a tutorial but encountered an issue when trying to add a submenu to the menu items. Instead of the submenu appearing only for the specific menu item hovered over, ...

The video is unavailable due to issues with ImageKit

In my project, I am incorporating ImageKit into the workflow. Currently, I have set up a basic process that only includes the video upload feature. On the backend, I have a lone file named index.js. I haven't developed a frontend yet, so I have been e ...

The var_dump($_POST) function is not displaying any results after submitting the form to the CodeIgniter controller

Can someone assist with my jQuery code? $(document).on("click", ".addthisone", function (e) { var file_data = $(this).parent().parent().parent().find('input[type=file]').prop("files")[0]; console.log(file_data); var form_data = new F ...

having trouble accessing a JavaScript array in AngularJS

Hey there, I'm currently working on a web application using AngularJS and I'm facing an issue with querying arrays. Check out the code snippet below: var angulararray = []; bindleaselistings.bindleaselistingsmethod().then(function(response) { ...

Encountering a GET-error while trying to nest jQuery/json calls: Resolution Update

My goal is to utilize services for ip-lookup and geo-lookup to pinpoint a visitor's location on a map. This information will be stored in a database and used to display live user locations on a dashboard. Currently, I am working on a script that, whe ...

Here's a unique version of the text: "Learn how to customize a datepicker to display only the next 3 months as a dropdown starting from the current date. Once the current

How can I limit the date picker to show only 3 months as a dropdown starting from the current date? $(function() { $("#date").datepicker({ hideIfNoPrevNext: true, minDate: '0M', maxDate: '+90D' }); }); <link rel="s ...

What could be causing Highchart to return the error message "Typeerror: undefined variable byte"?

My current project involves creating a graph using highchart and updating values every second. I am also working on displaying data in Mb, Kb, and Gb format on the graph by developing a function to convert byte values. Here is a snippet of my code: // hi ...

Combining Django Bootstrap input-group-addon with Model Form for seamless field integration

Currently, I am displaying my Django form in the following manner: <form action="/student/" method="post"> {% csrf_token %} {% bootstrap_form form %} <input type="submit" value="Launch" class="btn btn-primary"/> </form> I ha ...

What could be causing the issue of only the title being visible and not the content in Next.js when using next-mdx-remote?

I am having an issue with rendering MDX content on a page using next-mdx-remote with Next.js. Currently, only the title from the frontmatter is being displayed, while the actual MDX content is not showing up. Below is the code snippet showcasing my setup: ...

Using TypeScript to create a list of key-value pairs, which will be converted into a list of objects

Is there a more elegant way to transform an array of key-value pairs into a list of objects in TypeScript? let keys : string [] = ["name", "addr", "age"]; let values : string [][] = [["sam", "NY", "30"],["chris", "WY", "22"],["sue", "TX", "55"]]; The desi ...

What is the reason behind the sorting of sets in jQuery when using the .add() method?

Recently, I encountered an issue while adding multiple DOM objects (SVG elements) totaling around 3000 to an empty jQuery set using the .add() method. The process was taking an unexpectedly long time, causing the UI to freeze while the JavaScript code wa ...

Display a custom dropdown menu depending on the value chosen from a separate dropdown menu

There are three dropdown lists, each enclosed in its own DIV container. The DIV containers are named fromCity, WithinStateLimits, and OutOfState. The goal is to use the jQuery script below to hide the other two DIVs when a user selects an option from the ...

What is the proper way to implement v-model for a custom component within the Vue render function?

Below is the code that I am working with: ... var label_key_map = { a: "1", b: "2", c: "3", d: "4" } render: (h) => { var form_data = {} for (let key in label_key_map) { var form_item = h( 'FormItem', {props: {prop: key}}, ...

What is the reason for the React component being rendered four times?

My React component is fetching data from Firestore and storing it in the items array. However, I am encountering an issue where the menus variable contains three empty arrays that are being rendered on the page. Initially, I used an async function to fetc ...

Encounter issue when using GAS withSuccessHandler function

I've developed a Google Sheets add-on that utilizes a modal dialog for the user interface. I encountered an issue with the success handler not running as expected, so I created a basic test interface to troubleshoot the problem. After the server-side ...

When using i18next interpolation in React components, the displayed output may show as [object Object]

In my React application, I am utilizing the next-i18next package. I want to include a React component within my interpolation: import React from 'react'; import { useTranslation } from 'next-i18next'; import { serverSideTranslations } f ...

Ways to send selected options from a dropdown menu to the template in Django

Despite my extensive search efforts, I have not been able to find a clear answer to my current problem. Currently, I am displaying the first 5 items from a database and aiming to implement a feature that allows users to toggle between ascending and descend ...

Managing the size of personalized shapes in Three.js

I need help with a custom object that represents a frame created by subtracting two meshes. generateFrame (width, height, depth) { const frameMesh = new THREE.Mesh(new THREE.BoxGeometry(1, 1, 1)); frameMesh.scale.set(width, height, depth); c ...

using eloquent in vuejs to fetch database columns

I am currently attempting to retrieve data from a database using an AXIOS get request. I have two models, Content and Word, which have many-to-many relationships. In my controller, I am trying the following: public function fetchCourses(){ $dayOne = C ...