Summary of php related issues

小云云
Release: 2023-03-22 11:04:01
Original
1433 people have browsed it

This article mainly shares with you a summary of PHP-related issues, mainly the problems we usually encounter. I hope it can help everyone.

1. Talk about your understanding of JavaScript closures?

Simply put, it is the application of scope: local variables and global variables.

Variables defined inside the function cannot be accessed outside the function, so the function is said to constitute a closure.

2. How to solve the AJAX cross-domain calling problem?

Two methods: 1. Server side:

Use the Access-Control-Allow-Origin header on the request page

                    header("Access-Control-Allow-Origin: http://www.abc.com"); //允许指定网站
                    header("Access-Control-Allow-Origin: *");//允许所有网站
                    2.jsonp
Copy after login

ajax.js file:

  <script type="text/javascript">
    $.ajax({
        dataType: "jsonp",
        url: "http://www.b.com/b.php",
        jsonp: "callback",
        success: function(data) {
            $(".info").text("uid:" + data.uid + " name:" + data.name);
        }      
    });
    </script>
ajax.php文件:
<?php 
$callback = !empty($_GET[&#39;callback&#39;]) ? trim($_GET[&#39;callback&#39;]) : &#39;&#39;; 
if(!empty($callback)) {
    $data = json_encode(array(
        &#39;uid&#39; => 1,
        &#39;name&#39; => &#39;测试&#39;,
    ));   
    echo "{$callback}({$data});";
}
Copy after login

3. What is the difference between AJAX asynchronous and synchronous?

Asynchronous: When this AJAX code is running, other codes can also run. Synchronization: Wait for this ajax code to finish running before executing other functions. Set by async:false parameter, default true (asynchronous).

4. Talk about your understanding of MVC?

M(Model): Business rules for data V(View): The interface that users see and interact with C(Controller): Receive user data and call models and views to complete user needs.

Summary:

The model sends the functions to be implemented to the controller, and the controller receives the organizational functions and passes them to the view;

5. How to understand Single entrance and multiple entrances?

Single entrance: All requests of the web program are directed to a script file. Multiple entries: Complete user requests by accessing different files.

Related recommendations:

Concurrency - PHP questions for newbies

PHP question collection

php problem

The above is the detailed content of Summary of php related issues. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template