简体   繁体   English

您如何在方法中调用javascript函数

[英]how do you call a javascript function within a method

I am working with Zendframework 1 . 我正在使用Zendframework 1

On my view page, I used a JavaScript function * (JavaScript base64 encoder) *to encode some values: the function encrypts data that is transferred from one application to another. 在我的视图页面上,我使用了JavaScript函数* (JavaScript base64编码器) *对某些值进行编码:该函数对从一个应用程序传输到另一应用程序的数据进行加密。

I then want to send those value via a form to a method held within my controller. 然后,我想通过表格将这些值发送到控制器中保存的方法。 All of this should, in theory work fine. 从理论上讲,所有这些都可以正常工作。

My problem is this: once the value is received within my controller, I then need to decode it. 我的问题是:一旦在控制器中接收到该值,就需要对其进行解码。 So, I obviously need to attach a JavaScript function within my method that will enable me to then decode the information received. 因此,显然,我需要在我的方法中附加一个JavaScript函数,使我能够对接收到的信息进行解码。

Perhaps it might be easier if I show you what I am trying to achieve. 如果我向您展示我要实现的目标,也许会更容易。

The form values with the enclosed values 带有封闭值的表单值

<form action="#" method="post">

 <textarea name="txtstr" id="txtstr" cols="26" rows="5" Value="dGhlIGVuY2xvc2VkIHZhbHVlcyA="  ></textarea> 
<submit id="btnencode64">Encode</button><br/><br/>
</form>

The script for encoding the values 用于编码值的脚本

<script src="<?= $this->baseUrl() ?>/js/baseSixtyFourEncoder.js" type="text/javascript"></script>

The method within a controller 控制器内的方法

 public function ppAction()
 {
  $text = base64_decode($this->getRequest()->getParam('txtstr'));
 }

The issue now really is that I need to be able to use the JavaScript function once the form is received at the ppAction(). 现在的问题实际上是,一旦在ppAction()接收到表单,我就需要能够使用JavaScript函数。

Is it possible to use the JavaScript function in this way. 是否可以通过这种方式使用JavaScript函数。 I realise that PHP and JavaScript cannot really be used at the same time. 我意识到PHP和JavaScript不能真正同时使用。 But is it possible to use JavaScript in this contact? 但是可以在此联系人中使用JavaScript吗?

You cannot use a JS function in your PHP. 您不能在PHP中使用JS函数。 PHP (server side scripting) is used to generate the page while Javascript (client side scripting) is used for the interactions within the page. PHP(服务器端脚本)用于生成页面,而Javascript(客户端脚本)用于页面内的交互。

The following site tries to explain it a little bit more in details: http://wiki.answers.com/Q/What_are_client_side_and_server_side_scripting 以下站点尝试对其进行详细说明: http : //wiki.answers.com/Q/What_are_client_side_and_server_side_scripting

You might also want to check this SO post for details about base64 en/de coding: How can you encode a string to Base64 in JavaScript? 您可能还需要查看此SO帖子,以获取有关base64编码的详细信息: 如何在JavaScript中将字符串编码为Base64?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 nodejs 从 javascript 中的方法中调用递归方法? - How do you call a recursive method from within a method in javascript with nodejs? 如何在addEventListener()调用中调用对象方法? - How do you call a object method from within an addEventListener() call? Javascript - 如何从该类中调用类中的函数? - Javascript - How do you call a function inside a class from within that class? Javascript原型:如何在另一个方法中调用一个方法? - Javascript prototype: how do I call a method within another method? 您如何在HTML中正确调用JS函数? - How do you properly call a JS function within HTML? 如何在JavaScript保证字符串中使用.then函数中的参数调用函数? - How do you call a function with parameters in a .then function in a JavaScript promise string? 如何在函数定义中不使用“ this”的情况下使用bind()方法? - How do you use the bind() method without “this” within the function definition? 你如何在shiny中的htmlwidget(jsoneditor)上调用javascript方法? - How do you call a javascript method on a htmlwidget (jsoneditor) in shiny? 如何在页面加载方法内调用Javascript函数? - How to call a Javascript function within page load method? 如何在JavaScript中的函数中选择随机变量? - How do you select a random variable within a function in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM