怎么将php函数传递到js使用
如何将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数据!
但是普通的字符串处理建议别放服务端,增加了服务端压力!尽量在客户端处理!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c
