0

I have a small program which HTML and javascript in front end and PHP backend. The javascript sends POST to PHP to create, update tasks. So i want to run the program locally as there are some issues to be resolved. However when i run, it does not do the create task and results in error: enter image description here

IS there anything i need to do get this running. Thanks in advance. Edit: Adding a portion of javascript code to POST to php page:

$.post("model.php", {
            'task': 'write',
            'elementname': door
        }).done(function () {
            location.href = '?' + door;
        });

enter image description here

Installed XAMPP but getting the following error:

Community
  • 1
  • 1
sina123
  • 189
  • 1
  • 1
  • 13
  • Please give more info!!, What are you tring to do, and show some code! – ikenas May 25 '20 at 09:50
  • @VasylYovdiy Added to post. – sina123 May 25 '20 at 10:01
  • Run your code with an e.g. local Apache Server like xampp and it will work. The error is writen in your console "blocked by CORS policy" (default Browser security) – Richard May 25 '20 at 10:13
  • @Richard I have installed XAMPP and now its running. But still i get the same error in my console. I am new to the php thing and i have a doubt regarding how to load the HTML file. I just opened my local file. Is there a different way to run the html file when using the server? Could you please guide on that. – sina123 May 25 '20 at 12:53

1 Answers1

0

I think you tring to execute php code without having a server and this is not posible.

You should install XAMP or something similar.

Also there is now a way to run php locally without installing a server:

PHP server on local machine?

ikenas
  • 411
  • 3
  • 11
  • I tried installing XAMPP but unable to run Apache. Attached screenshot to post – sina123 May 25 '20 at 10:32
  • I would recoment to reinstall XAMP following some tutorial step by step! Try this one for Windows: https://blog.templatetoaster.com/install-xampp-on-windows/ – ikenas May 25 '20 at 10:53
  • I got it workinng finally. Found a useful video :https://www.youtube.com/watch?v=TjFRTkw6GDQ – sina123 May 25 '20 at 13:00
  • Thanks to all suggesting installation of server.. running html with php backend was new to me.. – sina123 May 25 '20 at 13:01