【问题标题】:to get response from external webservise that should only refresh part of the my joomla webpage从外部 webservise 获得响应,该响应应该只刷新我的 joomla 网页的一部分
【发布时间】:2013-08-07 09:03:14
【问题描述】:

我是 joomla 的新手。我使用了一个在此处显示的链接作为我的 Web 服务:http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius。 然后实现了一个代码来向 Web 服务发布一些值并得到响应,但是当我尝试将响应值设置为表单时,它会重新加载我托管的 joomla 站点的整个页面并显示空表单,因为刷新了网页。然后将值设置为空。它没有在表单中显示答案,因为我使用条件来检查表单属性是否为空,它应该显示空表单,但我可以使用“echo $response;”显示响应值在重新加载表格之前。我尝试使用会话,但这不是解决方案。谁能帮我解决这个问题。

<?php
if (isset($_POST['Fahrenheit'])&&$_POST['Fahrenheit']!=null) {
  $res = print_name($_POST['Fahrenheit']);
  print_form($res);
}
else {
  if($res == "")
  print_form($res);
}

// In this function we print the name the user provided.
function print_name($name) {
  $ch = curl_init();
  $far = 'Fahrenheit='.$name;
  curl_setopt($ch,            CURLOPT_URL,"http://www.w3schools.com/webservices/tempconvert.asmx/FahrenheitToCelsius");
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS,$far);
  // receive server response ...
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  $server_output = curl_exec ($ch);
  curl_close ($ch);

 return $server_output;
}

// This function is called when no name was sent to us over HTTP.
function print_form($val) {
  echo '
    <form method="post">
    <table>
      <tr>
        <td>Fahrenheit to Celsius:</td>
        <td><input class="frmInput" type="text" size="30" name="Fahrenheit"></td>
      </tr>
      <tr>
        <td></td>
        <td align="right"><input name="cel" type="submit" value="Submit" class="button"></td>
     </tr>
     <tr>
       <td></td>
       <td align="right">'.$val.'</td>
     </tr>
   </table>
   </form>
    ';
}

【问题讨论】:

  • 请在您的问题中添加一些相关代码。

标签: html xml web-services joomla http-post


【解决方案1】:

重新加载时,您的页面正在再次调用服务。将代码 sn-p 添加到问题中以找出问题的位置和原因。

【讨论】:

  • 我上传了我的代码。我没有任何想法这样做。我搜索了很多链接。但它不能正常工作。请给我一个与匹配的代码 sn-p 的解决方案我的 joomla 代码。
  • 我用 ajax 测试了另一个代码来刷新另一个 php 文件,但没有刷新表单就得到了响应。但这给了我另一个问题。我可以将该文件上传到服务器。但 joomla 不支持它。我没有在joomla后端上传。因为它应该作为文章上传。它也不支持php