Skip to main content
Known Participant
November 26, 2020
Answered

error code {"code":"MethodNotAllowedError","message":"POST is not allowed"}

  • November 26, 2020
  • 8 replies
  • 2207 views

I'm getting this error code 

{"code":"MethodNotAllowedError","message":"POST is not allowed"}

when I preview my javascript code on web preview. I've asked many people for help but no one knows how to fix it.

 

Any ideas?

I should also mention that I am very inexperienced with Javascript so dumbed-down advice would be appreciated.

    This topic has been closed for replies.
    Correct answer BenPleysier

    The external javascript as well, sorry I couldn't send a link to the files themselves,I'm not really sure how to do that.

    function calculate(){
    		'use strict';
    		var volume;
    		var radius = document.getElementById('radius').value;
    		radius = Math.abs(radius);
    		volume = (4/3) * Math.PI * Math.pow(radius, 3);
    		volume = volume.toFixed(4);
    		document.getElementById('volume').value = volume;
    		return false;
    	}
    	function init (){
    		'use strict'
    		document.getElementById('theform').onsubmit = calculate;
    	}
    	window.onload = init;

    Try

     

    <!doctype html>
    <html lang="en">
    
    <head>
        <meta charset="utf-8">
        <title>Volume of a Sphere</title>
        <style>
            body {
                padding-top: 30px;
            }
            label,
            input {
                display: block;
            }
        </style>
    </head>
    
    <body>
        <p>Input radius value and get the volume of a sphere.</p>
        <form action="" method="post" id="MyForm">
            <label for="radius">Radius</label><input type="text" name="radius" id="radius" required>
            <input type="submit" value="Calculate" id="submit">
            <label for="volume">Volume</label><input type="text" readonly name="volume" id="volume">
        </form>
        <script>
            function volume_sphere() {
            var volume;
            var radius = document.getElementById('radius').value;
            radius = Math.abs(radius);
            volume = (4/3) * Math.PI * Math.pow(radius, 3);
            volume = volume.toFixed(4);
            document.getElementById('volume').value = volume;
            return false;
            } 
            window.onload = document.getElementById('MyForm').onsubmit = volume_sphere;    
        </script>
    </body>
    
    </html>

    8 replies

    Known Participant
    December 4, 2020

    Thanks all for the help, I really appreciate all of you taking the time out of your day to fix this problem 

     

    Again thank you and God bless

    Known Participant
    December 4, 2020

    thanks very much! This code worked for me. I think in addition with changing some of the browser preview setting the problem is fixed.

     

    Again thanks heaps

    B i r n o u
    Legend
    December 3, 2020

    In the first video, you have twice file called sphere.html, and none of thema are located in the file panel... do the files are include in one of the two folders present ?

     

    do you have de web site declared ?

     

    the folder called Tony... has a lot of space in the filename, which can cause a lot of trouble

     

    and could you try using a different browser... I think that Ben also propose it

     

     

    Jon Fritz
    Community Expert
    Community Expert
    December 3, 2020

    Could be because you are using Adobe's servers to preview.

    Go to Edit > Preferences > Real-Time Preview and check the box for Default to Static Browser Preview

    ...then preview the page and see if that does the trick.

    B i r n o u
    Legend
    November 30, 2020

    well, I copied and pasted your HTML into a file, then I copied and pasted the last Javascript I sent you, I saved it in a sphere.js file that I placed at the same level as the HTML file.
    a preview in real time, and hop... it works as expected... you can get a zip archive and try directly with files that work for sure.. and see if it is DW the fault

    https://www.puce-et-media.com/pi-volume.zip

    Known Participant
    December 2, 2020

    Yup, I ran the program on Dreamweaver and I still got the same error. So that means it's definatley a dreamweaver error. this is strange as i've asked many, many people for help on this and no one really knows how to fix it, not even adobe themselves. Now I really don't know what to do

    Legend
    December 2, 2020

    At this stage I would dump the code supplied by myself or Birnou into a different code editor, like Brackets, Sublime Text or VS code, all are free to download if you search for them in Google, and see if the code works.

     

    Although it could be a Dreamweaver issue its unlikely, the code is simple enough. The problem is your original code was so badly written, full of errors and mistakes, I think we are all finding it difficult to know if you have actually copied and pasted the code supplied correctly, without introducing further errors.

    B i r n o u
    Legend
    November 30, 2020

    well multiple errors in the code... can you try fixing them, and try again ?

     

    1. GetElementById doesn't start with an upper case, it is getElementById, so replace the three of them
    2. radius = Math.abs('radius'); you must call the variable radius and not the string 'radius', so remove the quote
    3. volume = (4/3) * Math.PI * Math.pow(radius.value, 3); radius is already a number value and doesn't contains any value property, so remove the .value
    4. volume.tofixed(4) should be wrote volume.toFixed(4), with the F in uppercase
    5. one (which is not blocking), on the last sentance of the calculate function, you have a space bteween the dot and value

     

    so the code should be now

     

     

    	function calculate(){
    		'use strict';
    		var volume;
    		var radius = document.getElementById('radius').value;
    		radius = Math.abs(radius);
    		volume = (4/3) * Math.PI * Math.pow(radius, 3);
    		volume = volume.toFixed(4);
    		document.getElementById('volume').value = volume;
    		return false;
    	}
    	function init (){
    		'use strict'
    		document.getElementById('theform').onsubmit = calculate;
    	}
    	window.onload = init;

     

    Known Participant
    November 30, 2020

    Thanks for the help, I did everything you said but im still getting the error message, I'm not sure if this is a fault with my code or with dreamweaver?

     

    Perhaps its with my HTML, here it is if that helps

    <!doctype html>
    <html lagn="en">
    <head>
    <meta charset="utf-8">
    <title>Untitled Document</title>
    <!--[if lt IE 9]>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link rel="stylesheet" href="sphere.css">
    </head>
    
    <body>
    	<!-- sphere.html -->
    	<form action="" method="post" id="theform">
    		<fieldset>
    			<p>Use this form to calculate the volume of a sphere.</p>
    			<div><label for="radius">Radius</label><input type="text" name="radius" id="radius" required></div>
    			<div><label for="volume">Volume</label><input type="text" name="volume" id="volume"></div>
    			<div><input type="submit" value="calculate" id="submit"></div>
    		</fieldset>
    	
    	</form>
    	<script src="sphere.js"></script>
    </body>
    </html>
    Legend
    November 30, 2020

    There's nothing much wrong with your html as far as I can see that would cause you to keep getting an error.

     

    Can you copy the code below, paste it into a new Dreamweaver document and save it as calculate_volume.html

     

    View in browser and enter a number in the 'Radius' input form field then click the 'calculate' button.

     

    Do you get the result written to the 'Volume' input form field?

     

     

    <!doctype html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Calculate Volume</title>
    <link rel="stylesheet" href="sphere.css">
    </head>
    <body>
    <!-- sphere.html -->
    <form action="" id="theform">
    
    <fieldset>
    <p>Use this form to calculate the volume of a sphere.</p>
    
    <div>
    <label for="radius">Radius</label>
    <input type="text" name="radius" id="radius" required></div>
    <div>
    
    <label for="volume">Volume</label>
    <input type="text" name="volume" id="volume">
    </div>
    
    <div>
    <input type="submit" value="calculate" id="submit">
    </div>
    
    </fieldset>
    
    </form>
    <script>
    function calculate(){
    'use strict';
    var volume;
    var radius = document.getElementById('radius').value;
    radius = Math.abs(radius);
    volume = (4/3) * Math.PI * Math.pow(radius, 3);
    volume = volume.toFixed(4);
    document.getElementById('volume').value = volume;
    return false;
    }
    function init(){
    'use strict'
    document.getElementById('theform').onsubmit = calculate;
    }
    window.onload = init;
    </script>
    </body>
    </html>

     

     

    Nancy OShea
    Community Expert
    Community Expert
    November 26, 2020

    If you know nothing about code, where did this code come from?

     

     

    Nancy O'Shea— Product User & Community Expert
    Known Participant
    November 27, 2020

    Sorry, what I meant was that I am a student studying web design, and I am now learning javascript. I haven't gotten very far into my lessons when I encountered this error.

    Legend
    November 27, 2020

    First lets establish what workflow you are using - php, node.js, something else?

     

    Are you trying to process some form information when this error occurs?

     

     

     

    Legend
    November 26, 2020

    This doesnt have much to do with javascript but the php you are using to process the form. Are you testing on a local server? To run php you have to either have a local testing environment set up like XAMPP or MAMP, both are freely available to download from the internet, or your remote server should be enabled to run php.

    Known Participant
    November 27, 2020

    I dont believe Im using a server at all. I tried downloading XAMPP and MAMP, but I don't know how to use them at all. Any advice please? Im at my wits ends.