How to quote A. php file in a. js file?

Source: Internet
Author: User
Online and other help, suppose my js file called a.js,php file is called b.php, novice do not spray ~ ~


Reply to discussion (solution)

JS may not be called directly, but you can use the script tag to introduce PHP

The HTML page looks like this:



b.php:
 
  



JS Asynchronous call PHP I know, you said this is the case??

JS is not able to parse PHP

You can change a way to think since JS can not parse that will make PHP into class you in JS inside new under the line
Take an example/**
* Adloader
* Iwebshop's ad Loader
*
* First introduce this JS, then load ads, 1 is the ID of the ad bit
*
*
* 广告......
*
*

* @author Lulutang
*/

In the JS file you want to refer to the PHP file, if the php file content is output JS code, you can use var a = document.createelement (' script '); a.src= ' b.php '; Such dynamic loading JS method load.
If only the PHP file returns a value, use the Ajax method to return the JSON format.

a.php



For b.php
Include ' a.php '; Replace

I think you put why you have to quote PHP in the purpose of the script is what more to solve your problem, is to understand why JS to reference a PHP file, what is the point

In the HTML or PHP page definition, in the JS file reference this URL variable can be

JQ Code

$.get (' b.php ', function (data) {//Here data is the return value of PHP  alert (data);});

PHP code
 
  

Didn't learn anything.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.