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

时间:2020-02-07 22:18:30

标签: 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);
   }

1 个答案:

答案 0 :(得分:1)

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

相关问题