Highlighted

trouble with animate cc html5 and php

New Here ,
Mar 17, 2019

Copy link to clipboard

Copied

I have a code in animate like this:

$.ajax({

     type: "POST",

     url: stage.path + 'php/s1.php',

     data: "Pippo",

     success: function (data) {

          alert(data)

     }

})

and the file php like this:

<?php

     $var=$_POST["var1"];

     echo $var;

?>

The code never show the alert....

Views

619

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

trouble with animate cc html5 and php

New Here ,
Mar 17, 2019

Copy link to clipboard

Copied

I have a code in animate like this:

$.ajax({

     type: "POST",

     url: stage.path + 'php/s1.php',

     data: "Pippo",

     success: function (data) {

          alert(data)

     }

})

and the file php like this:

<?php

     $var=$_POST["var1"];

     echo $var;

?>

The code never show the alert....

Views

620

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 17, 2019 0
Adobe Community Professional ,
Mar 17, 2019

Copy link to clipboard

Copied

are you initializing jquery before your code executes?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
New Here ,
Mar 17, 2019

Copy link to clipboard

Copied

Excuse but i don't know very well english....

I have a code...

But i don't receive the answer of php...

It's ever in error...

but the php work well because if I launch that php with some save he execute that...

the problem is only the answer... the ECHO of PRINT or PRINT_R don't work as I expect

And I don't know if jquery is initialized..

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
Adobe Community Professional ,
Mar 17, 2019

Copy link to clipboard

Copied

that's the problem:  you're using jquery and you don't understand how to use it.

open your html file and check that you have something like

<script src="http://code.jquery.com/jquery-some_version_number.min.js"></script>

before your animate js is called

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
Adobe Community Professional ,
Mar 17, 2019

Copy link to clipboard

Copied

Hi.

Besides jQuery, as kglad suggested, make sure your server has support to PHP.

As far as I can tell, the default local server that Animate setups for testing doesn't support PHP.

So you're gonna have to use another local server like XAMPP or an online server with this kind of support.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
New Here ,
Mar 17, 2019

Copy link to clipboard

Copied

That code isn't present on my html code...

But how to learn this?

I worked only with flash as3...

And there are no many articles about this

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
New Here ,
Mar 17, 2019

Copy link to clipboard

Copied

I use a EasyPHP 5.4.6

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 17, 2019 0
New Here ,
Mar 18, 2019

Copy link to clipboard

Copied

This night i put my work in a website and todo works fine....

Now my question is: why the same work don't work with easy php or xampp? Obviously i write localhost or 127.0.0.1 but never work as expected and the path us correct...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 0
Adobe Community Professional ,
Mar 18, 2019

Copy link to clipboard

Copied

Hi.

I usually use XAMPP and it works without a problem.

Make sure to start the Apache server and even MySQL if your script will depend on MySQL database to run.

https://www.techwalla.com/articles/how-to-run-a-php-file-in-xampp

Another thing is that you don't need jQuery to send a POST request. You can use XMLHttpRequest like this:

JavaScript file:

var xhr = new XMLHttpRequest();

xhr.open("POST", 'test.php', true);

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

xhr.onreadystatechange = function ()

{

    if (this.readyState === XMLHttpRequest.DONE && this.status === 200)

        console.log("sucess", this.responseText);

}

xhr.send("foo=bar&lorem=ipsum");

PHP:

<?php

  if ($_POST["foo"])

      echo $_POST["foo "];

  if ($_POST["lorem"])

      echo $_POST["lorem"];

?>

I hope this helps.

Regards,

JC

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 1
New Here ,
Mar 18, 2019

Copy link to clipboard

Copied

Nothing... The answer is this:

Access to XMLHttpRequest at 'http://127.0.0.1/leoschool/php/salvataggi.php' from origin 'http://127.0.0.1:8090' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 0
Adobe Community Professional ,
Mar 18, 2019

Copy link to clipboard

Copied

This doesn't mean your PHP is not working.

This issue happens because you're requesting a PHP that is not in the same location of your html. You need to allow cross origin in the JavaScript and in the PHP file.

But, only for development purposes, you can install an extension in the browser that allows cross origin requests very easily.

Allow-Control-Allow-Origin: * - Chrome Web Store

CORS Everywhere – Get this Extension for    Firefox (en-US)

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 0
New Here ,
Mar 18, 2019

Copy link to clipboard

Copied

But I have this in my browser and is the same

And my file php isn't in the same folder of my web site but  in php folder... but the same computer and the same website...

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 0
Adobe Community Professional ,
Mar 18, 2019

Copy link to clipboard

Copied

Use a relative path if your php is under the same root directory of your app/page. Like:

/php/salvataggi.php

__________________________________________
HTML5, JSFL, and AS3 samples: http://bit.ly/2mJgDoG

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 18, 2019 1