最近在学习discuz,其中修改代码时想把js的值赋值给discuz的全局变量,有木有大神知道可以怎么做?或者用php的方法来获取js的值也可以
回复讨论(解决方案)
php获取的不是js的值,而是js传递到服务端的值!前端可以通常通过两种方式把数据传递到后端:POST GET
$user = $_POST['user']; //php中获取post值$pass = $_GET['pass']; //php中获取get值
而传值一般通过ajax的方式传递!
所以并不是php获取了js的值,而是js将数据传递到服务端,然后php读取post get等全局数组!
php获取的不是js的值,而是js传递到服务端的值!前端可以通常通过两种方式把数据传递到后端:POST GET
$user = $_POST['user']; //php中获取post值$pass = $_GET['pass']; //php中获取get值
而传值一般通过ajax的方式传递!
所以并不是php获取了js的值,而是js将数据传递到服务端,然后php读取post get等全局数组!
就比如说我在当前页面写了一个JS,然后想在当前页面中得到这个值,该怎么写?
你所说的一般用ajax传递,页面的执行顺序是先等php语言解析完成再开始执行解析后的html代码、
你所说的一般用ajax传递,页面的执行顺序是先等php语言解析完成再开始执行解析后的html代码、
这个可以怎么写?
你所说的一般用ajax传递,页面的执行顺序是先等php语言解析完成再开始执行解析后的html代码、
这个可以怎么写?
你是把html php 和js都写在一起了? 建议把各个文件分离!
http://www.w3school.com.cn/php/php_ajax_suggest.asp w3上的实例
你所说的一般用ajax传递,页面的执行顺序是先等php语言解析完成再开始执行解析后的html代码、
这个可以怎么写?
你是把html php 和js都写在一起了? 建议把各个文件分离!
http://www.w3school.com.cn/php/php_ajax_suggest.asp w3上的实例
不是我写一起了,是在dz上直接修改,我也没办法啊
先弄清楚,服务端跟客户端的执行顺序
php是属于服务端的语言
而JS是客户端的脚本
都是服务端先执行完才会到客户端的,所以你要让服务端去获取客户端的值,唯一的办法,就是让客户端发送请求到服务端
比如使用ajax方式请求
先弄清楚,服务端跟客户端的执行顺序
php是属于服务端的语言
而JS是客户端的脚本
都是服务端先执行完才会到客户端的,所以你要让服务端去获取客户端的值,唯一的办法,就是让客户端发送请求到服务端
比如使用ajax方式请求
在同一个页面里面也可以这么做吗?
应该是用ajax请求的方式传递到php里面处理吧
应该是用ajax请求的方式传递到php里面处理吧
问题是是在discuz里面进行的,普通的php,用ajax就可以了
discuz 不是提供有 ajax.get 方法吗?
discuz 不是提供有 ajax.get 方法吗?
刚学discuz,不是很熟悉,能简单举个例子吗?就比如说我要做一个下拉框,然后想把下拉框的value赋值给$_G['fid']
其实我没有过 discuz,你看看这个 http://www.baidu.com/s?ie=UTF-8&wd=discuz+ajax%E4%BD%BF%E7%94%A8
其实我没有过 discuz,你看看这个 http://www.baidu.com/s?ie=UTF-8&wd=discuz+ajax%E4%BD%BF%E7%94%A8
好的,我去看看,谢谢
用ajax来传递到php
用ajax来传递到php
小白,能给个实例吗?
<?php $num = "<script> var num = 123;document.write(num);</script>";echo $num;?>
php这样就可以使用js的变量值
<?php $num = "<script> var num = 123;document.write(num);</script>";echo $num;?>
php这样就可以使用js的变量值
好的,谢谢

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version
