javascript - 脚本标签中可以使用 PHP 代码代替 javascript 吗?

标签 javascript php

我对 PHP 编码非常陌生。我想在我的网站上安装事件触发器,但我无权访问主 PHP 脚本。但我可以构建 JavaScript 模板。看看这段代码似乎与 Javascript 类似 - 我想知道我是否可以将其设置为 javascript。这段代码应该从访问特定站点的客户那里获取 ID,一旦检索到 ID,API 就会触发自动工作流程。然后触发一个事件。

 <?php
 /**
 * This example will obtain the id for a contact and then
 * add that contact to a workflow by calling
  * addContactEvent. In order for a contact to
 * be added to a worklow, the workflow must contain
 * the Received API Event trigger node. The Received
 * API Event trigger node contains a keyword. This 
 * keyword is used to reference that workflow using 
 * API call. Note that more than one workflow can have 
 * the same keyword. In this case, the contact will be
 * to each workflow containing the specified keyword.
 */ 

  $client = new SoapClient('https://api.bronto.com/v4?wsdl', array('trace' => 1, 
                             'features' => SOAP_SINGLE_ELEMENT_ARRAYS));

      try {

 // Add in a valid API token
  $token = "ADD API TOKEN HERE";

  print "logging in\n";
  $sessionId = $client->login(array('apiToken' => $token))->return;

   $session_header = new SoapHeader("http://api.bronto.com/v4",
               'sessionHeader',
               array('sessionId' => $sessionId));
   $client->__setSoapHeaders(array($session_header));

  // Obtain the contact id for the contact being added to 
  // the workflow. You can always add more than 1 contact 
  // using addContactEvent if need be.

  // Set up a filter to read contacts 
 $filter = array('type' => 'AND',
      'email' => array('operator' => 'EqualTo',
              'value' => 'SOME EXAMPLE EMAIL ADDRESS')
                   );

  print "reading contacts with equalto filter\n";
  $contacts = $client->readContacts(array('pageNumber' => 1,
                  'includeLists' => false,
                  'filter' => $filter,
                  )
                )->return;
    if (!$contacts) {
   print "There was an error reading your contacts. Please review your request and try again.\n";
   exit();
   } 


  // Specify the keyword assigned to the Received API 
  // Event trigger node(s) added to the workflow(s) you want 
 // to add contacts to.
    $keyword = 'SOME EXAMPLE KEYWORD';

 print "Adding contacts to the workflow\n";

 $write_result = $client->addContactEvent(array('keyword' => $keyword, 
                       'contacts' => $contacts)
                  )->return;

  if ($write_result->errors) {
  print "There was a problem adding the contacts to the workflow:\n";
  print_r($write_result->results . "\n");
  } else {
   print "The contacts have been added to the workflow.";
   print_r($write_result->results);
   }

   } catch (Exception $e) {
   print "uncaught exception\n";
   print_r($e);
   }

最佳答案

不,网络浏览器不包含 PHP 解释器,它们只能读取 Javascript。如果您希望从浏览器执行代码,您需要用 javascript 或 Web 程序集编写它。

关于javascript - 脚本标签中可以使用 PHP 代码代替 javascript 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60121864/

相关文章:

javascript - 初始化后添加更多图像时,React-slick slider 会变形

javascript - ASP.NET 中的 Web 部件是否有任何替代方案来创建可拖放内容,或与 Jquery 混合使用?

php - jQuery 数据表将日期显示为 [object Object]

javascript - React - 显示可变的行数

javascript - @JavascriptInterface 无法解析

javascript - 在再次调用之前销毁javascript中的函数

php - mysql查询后数组返回2个相同的元素,为什么?

php - 通过大学代理从本地 LAMP 连接到远程 MySQL 数据库

php - 基于高流量百分比的集合选择?

php - 如何在 nginx (Ubuntu 16.04) 上配置基本的 FastCGI 缓存