来自 Javascript 的变量 ->PHP ->聪明……有可能吗? [英] Variable from Javascript -> Php -> Smarty... is it possible?

查看:33
本文介绍了来自 Javascript 的变量 ->PHP ->聪明……有可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

示例:

<script type="text/javascript">
    insertVideos({
        'block':'youtubeDiv',
        'q':'keyword',
        'type':'search',
        'results':8,
        'order':'most_relevance',
        'player':'embed',
        'layout':'thumbnails'
    });
</script>

我需要将结果"作为要传递的变量,在流程结束时,我需要类似的东西:{if $results != 0}我该怎么做?

i need that 'results' as a variable to pass, at the end of process i need something like: {if $results != 0} how can i do it?

推荐答案

没有办法在您的 javascript 中访问 PHP/Smarty,因为它们在两个不同的世界中执行.

There isn't a way to access the PHP/Smarty in your javascript as they are executed in two different worlds.

该页面是从服务器请求的.服务器执行 PHP 并使用 Smarty 生成内容.服务器将生成的 HTML 和 javascript 源代码发送到客户端.服务器现已完成.如果收到另一个请求,它会在不知道前一个请求的情况下重新开始.

The page is requested from the server. The server executes the PHP and generates the content with Smarty. The server sends the resulting HTML and javascript source code to the client. The server is now done. If another request is received, it starts over anew without knowledge of the previous request.

客户端接收 HTML 和 javascript 源代码并显示.insertVideos 方法最终会得到调用.此时,它与服务器和 PHP/Smarty 功能没有交互.

The client receives HTML and javascript source and displays. The insertVideos method eventually gets calls. At this point, it has no interaction with the server and the PHP/Smarty features.

从那里,javascript 可以向服务器发出 ajax 请求,或者如果我假设您只想在搜索找到一些视频(results > 0)时显示视频,您可以在 javascript 中进行检查并根据需要添加/修改 dom 元素.

From there, the javascript could make an ajax request back to the server or if I make an assumption that you only want to display the videos if the search finds some (results > 0), you can make that check in javascript and add/modify the dom elements as needed.

这篇关于来自 Javascript 的变量 ->PHP ->聪明……有可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆