Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Neitrosha · Jan 07, 2016 at 05:23 PM · c#javascriptwwwphp

Is it possible to call a Javascript code on local server from Unity? (Google Chart API involved)

I am testing different ideas, so this is the problem I ran into.

I have two php scripts on my local server.

The first one does the following: It connects to a database and takes all of the values I need - dates and sales. After it connects to a database, I use Google Chart Api (I use standard JavaScript to call it) to create a chart with the values I got. Once the chart is created, I save the chart as a png (with the help of the second php file, which converts a base64 data string to an image) to my DB.

The problem I encountered is that I actually have no idea how to make this script run. I tried to use the WWW function;

 string query = linkToGetImageOfStats_str;
 
 WWW result_WWW = new WWW (query);
 yield return result_WWW;

but the only thing I would get is the actual code of that php file I am calling, without actually saving the image to my database, meaning - the JS code doesn't not get executed, even though it's part of that php-file. But when I actually run that script in the browser, everything is fine.

Any ideas? Thanks.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 08, 2016 at 01:37 PM

That sounds like you have a wrong view of what code is executed where. PHP is a "preprocessor language". It's ment to be included in an HTML document. The PHP interpreter recognises the PHP tags in the source file, executest some actions and removes those tags and might add something else at this place. In the end the source file is sent with all those modifications to the client.

Javascript inside a HTML document is never executed on the server. Those scripts are ment to be executed on the client by the internet browser how is able to read HTML, render that content and execute Javascript code inside those HTML files.

If you want your server to contact that google API you have to look for a PHP solution, maybe using cURL.

I never used that Chart API from Google but it seems there is a PHP implementation. So forget about Javascript.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Neitrosha · Jan 08, 2016 at 04:01 PM 0
Share

Wow, thanks for the answer and clear explanation!

avatar image
0

Answer by phil_me_up · Jan 07, 2016 at 09:57 PM

It sounds like your server isn't setup correctly if you're getting the php script contents returned. Are you using Apache? What happens if you visit that link in a browser?

Assuming your server is setup correctly, then you have the right idea. You make a WWW call to the address of your scripts and include any values you want to submit to that script as part of the query string or as a POST.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Neitrosha · Jan 08, 2016 at 08:49 AM 0
Share

I am using XA$$anonymous$$PP.

What happens if you visit that link in a browser?

Everything is fine then. I visit that link, php code gets the needed values, then I make a call to Google Charts Api with JavaScript. I think that's precisely the problem. When I use the WWW class, it gets the whole content of the page without executed JS code. It would be fine, if it was executed - I would stll be able to get the lines I need, but... So, what happens is that Javascript part of the script doesn't not get executed. This code just gets returned as a text, where I would get the html tags and javascript lines.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

60 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Printing "console.log" from an index.html file 0 Answers

how do i get the right url to be returned in www? 1 Answer

Sending variables to HTML 1 Answer

How do I know that php server is available? (C# script) 1 Answer

Why FormatException: Input string was not in the correct format? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges