gpt4 book ai didi

php - 保持 Javascript 和服务器代码同步

转载 作者:搜寻专家 更新时间:2023-10-31 21:17:41 24 4
gpt4 key购买 nike

到目前为止,我遇到的最常见的错误类别是 javascript 和服务器代码之间的接口(interface)问题。这包括让 javascript 调用错误的 URL,传递错误的数据(特别是如果需要传递的内容发生变化,而 javascript 没有),以及将数据转换为 html 的问题,就像我的应用程序所做的那样。

有没有简单的方法来处理这个问题?我目前正在使用 PHP 中的 Zend Framework 进行开发。我认为使用 Selenium 可以稍微避免前几个问题,但我不确定如何处理数据 -> html 问题。我很想拥有某种与我的 ZF View 助手等效的 javascript,但我不确定这有多大可能。

最佳答案

在设计良好的网站上,(公共(public))URL 不会改变。当然,您可以自由使用任何您想要的内部结构。

如果有必要,你应该能够像生成HTML一样生成JS。但是,如果您申请 proper REST principles :

A REST API should be entered with no prior knowledge beyond the initial URI (bookmark) and set of standardized media types that are appropriate for the intended audience (i.e., expected to be understood by any client that might use the API). From that point on, all application state transitions must be driven by client selection of server-provided choices that are present in the received representations or implied by the user’s manipulation of those representations.

当要针对 future 的重组制作文档操作证明时,请使用支持强大元素选择语言的库,例如 XPath 或 jQuery 的选择器,而不是遍历 DOM 结构并使用良好的 ID 和 class names这不会改变。

关于php - 保持 Javascript 和服务器代码同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5060889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com