如何将php函数传递到js使用
项目在后端php有一些字符串处理函数,或者是字符串合法性检测类
网页前端也需要用到,不想单独编写js代码,维护起来很麻烦,也会有细小的差异可能导致新问题
我的想法是在js和php两边各编写一个统一接口,定义一套函数调用的规则,函数名和参数如何传递等等,靠json返回结果
有这些疑问:
1.听说过webservice这个词,它指的是设计思想,还是实际的php模块呢?
2.这种通过网络调用函数的办法,安全和隐私怎样保证呢?我只想被自己的项目调用
3.这种办法有网络延迟,有没有更好的解决方案呢?
4.nodejs是否可以真正的实现前后端共用代码?可以放一个示例吗?
------解决思路----------------------
1. webservice的定义其实很宽,其实就是一种远程调用技术。
2. 基于身份验证,同域的后端与前段交互可以基于网站本身的用户身份验证,后端与后端的交互验证实现方式就多了
3. 简单的字符串处理等函数(不是基于依赖数据查询的复杂业务的)应该同样在js实现一个,网络问题没办法解决。
4. 基于web是不可能的。
其实楼主想要实现的东西, asp.net的控件早已经实现了.
------解决思路----------------------
在js和php两边各编写一个统一接口,定义一套函数调用的规则,函数名和参数如何传递等等,靠json返回结果
調用規則可以統一,但檢查的代碼還是要分開寫js和php 兩套啊
------解决思路----------------------
正常就是该这么做吧!
前端把敏感数据传过来,服务端处理完成返回json数据!
但是普通的字符串处理建议别放服务端,增加了服务端压力!尽量在客户端处理!

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi


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 Linux new version
SublimeText3 Linux latest version

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.
