POST request stopped working. Why?

I have an old Core running the same program for a few years now. My web page code uses javascript to send POST requests to control the core. This has worked flawlessly for a few years. Today it gives a 400 error in the browser debug console. Here is my code that worked for a long time:

var requestURL = "" + deviceID + "/" + web_com + "/";
$.post( requestURL, { params: message, access_token: accessToken });

What changed and what am I missing here?

Thanks for your help.

Could you show us the error message as well?

This prints out with the error symbol to the left.

POST" Device ID "/web_com/ 400

Ah, the first time I click a button on the web page and the error is thrown I see to the right of the above error:" Device ID "/web_com/:1

The second time and successive times I click the button, I see this to the right of the error:

Would you mind posting a Screenshot of those errors? That’s often more descriptive.

yeah, sorry. One moment…

This error comes up when I click a button that currently says “OFF”

Does your web page load a specific version of JQuery?

I have seen this type of error before and what happened was that JQuery 1.3.2 was no longer available and you would need to update to a newer version.


Thank you for your suggestion. This seemed to fix the problem. I was referencing an outdated JQuery. I updated to the current version 3.3.1 and it seems to be working great.


Well, I updated the JQuery version as noted, and it worked for over a month. Nothing has changed, but a similar error cropped up two days ago. Below is the error and some bare-bones code that is throwing it.

What changed to make it act up again?

        <script src="" type="text/javascript" charset="utf-8"></script>
    <button id="controlstate1" onclick="web_communication('A', 'C', '-1')" style="height:33px; width:80px; font-size:23px; cursor: pointer;">Toggle</button>
    <script type="text/javascript">
		//particle core related stuff (global)
		var deviceID    = "1234567890";
		var accessToken = "abcdefghijklmn";
        function web_communication(tank, action, new_value){
                        var message = tank + action + new_value;
                        //send the command to the Particle Core
                        var requestURL = "" + deviceID + "/" + "web_com" + "/";
                            $.post( requestURL, { params: message, access_token: accessToken });

I’m not sure–that version of jquery is the current version. Google no longer recommends the type="text/javascript" charset="utf-8" part but I don’t think it is hurting you.

You do not need that trailing “/” on the requestURL, but I believe that still works with it.

Have you checked your real access token and device ID for typos?

What browser is that? I would try Chrome or Firefox first and if you already using one of those two, try the other. If you are hosting this, what CORS policy does your host allow?

Thanks for the analysis. The browser is Chrome. Token and device ID are correct. I’ll clean up the type and charset stuff and see if it makes a difference.

I’m not very familiar with CORS, but from my reading, it seems that is a possible failure point of this code. I’ll look into it.

Thanks again…

There are a few Chrome Extensions that should fix the CORS problem.

Here is the one I use:

1 Like