重新加载页面以获取页面源错误,不知道出了什么问题

时间:2014-10-17 10:38:53

标签: ajax post zend-framework2 httpresponse hosted-app

您好我是zend框架的新手,我创建了一个应用程序,允许用户编辑图像并在图像中放入一些文本,所以我决定通过实现个人应用程序来学习zend框架,

我已将应用程序上传到托管服务器子域,但由于某种原因,我的应用程序与localhost不同。在localhost上工作正常但在托管服务器上我不知道什么是worng,但是在ajax成功之后有一些关于重定向localhost的问题。

问题如下。

问题1。

  1. 当我打开主页并单击自定义按钮时,它将显示一个包含表单的模型,其中包含四个输入字段,当我输入4行并单击预览按钮时,它将调用控制器个人鼠标和动作是预览,预览动作将从现有图像创建一个图像,该图像位于public / img /文件夹中,现在它不是将图像创建到文件夹public / img / image_uri而响应是空白页面,而在firebug中html消息是"重新加载页面以获取源"。当我重新加载页面时图像不存在,图像不在托管服务器上的public / img / image_uri文件夹中,并且会话未创建我认为预览操作有一些问题。但是我不知道我在哪里,我试图从4天开始谷歌但没有成功。
  2. 同样的事情是在localhost上工作。

    问题2

    1. 我想在单击preview.phtml页面上的保存按钮后重定向页面,现在我在控制器中有一个保存操作,它会将数据保存在localhost mysql数据库中,并且它正在重定向但只在firbug中, actuall页面没有重定向,我试图在ajax成功使用警报,但没有使用它没有显示消息。
    2. 请提前帮助和谢谢。我很感激我的代码更正。和一些代码示例。再次感谢。

      Index.phtml

          <div class="row top-buffer">
          <div class="span9">
              <div class="row">
                  <div class="col-md-4"><img src='<?php echo $this->basePath('img/whitemug toxic fox.jpg') ?>'class="img-responsive"/></div>
                  <div class="col-md-6">
                      <h3><strong>Personal Mug</strong></h3>
                      <h3><small>Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!</small></h3>
                      <a name="fulldescription">Read Full Description</a>
                      <div class="row top-buffer">
                          <div class="col-md-8">
                              <button class="btn btn-success btn-lg btn-block" data-toggle="modal" data-target="#myModal">Customize</button>
                          </div>
                      </div>
                      <div class="row top-buffer">
                          <ul>
                              <li>
                                  The mug has space for a maximum of 48 characters, over a maximum of 4 lines.
                              </li>
                              <li>
                                  Free Delivery when you spend over £40
                              </li>
                              <li>
                                  Guaranteed Fast, Secure Shipping
                              </li>
                          </ul>
                      </div>
      
                  </div>
              </div>
          </div>
      </div>
      <div class="row">
          <div class="col-md-6 ">
              <h3><strong>Personal Mug</strong></h3>
              <h4><small>Is your coach simply the best?</small></h4>
              <h4>Reward them with this amazing No.1 Coach Mug. This mug features a fabulous award design with the message COACH (any name) no.1! Make this thoughtful gift extra special and personal by adding your coaches name!</h4>
      
          </div>
      
          <div class="col-md-6 ">
              <?php foreach($personalmugs as $personalmug) : ?>
              <div class="col-md-3 top-buffer"> <a href="#">
                      <img src="<?php echo $this->basePath($this->escapeHtml($personalmug->image_uri)); ?>"  class="img-thumbnail img-responsive">
                  </a>
              </div>
              <?php endforeach; ?>
          </div>
      </div>
      <!-- Modal -->
      <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
          <div class="modal-dialog">
              <div class="modal-content">
                  <div class="modal-header">
                      <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
                      <h4 class="modal-title" id="myModalLabel">Submit text</h4>
                  </div>
                  <div class="modal-body">
                      <form class="form-horizontal" action="personal-mug/preview" role="form" method="POST">
                          <div class="form-group">
                              <label for="inputText" class="col-sm-2 control-label">Text</label>
                              <div class="col-sm-10">
                                  <input class="form-control" type="text" name="mugtext1" maxlength="12" placeholder=Line1 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required>
                                  <input class="form-control" type="text" name="mugtext2" maxlength="12" placeholder=Line2 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required>
                                  <input class="form-control" type="text" name="mugtext3" maxlength="12" placeholder=Line3 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required>
                                  <input class="form-control" type="text" name="mugtext4" maxlength="12" placeholder=Line4 pattern="^[a-zA-Z0-9\s]+" title="Only Alphabets and Numbers" min="1" max="12" required>
      
                              </div>
                          </div>
                          <div class="form-group">
                              <div class="col-sm-offset-2 col-sm-10">
                                  <button name="submit" value="submit" type="submit" class="btn btn-default">Preview</button>
                              </div>
                          </div>
                      </form>
                  </div>
              </div>
          </div>
      </div>
      

      预览phtml文件代码。

      <div class="row top-buffer">
          <div class="span9">
              <div class="row">
                  <div class="col-md-4"><img id="mug1" name="mug1" src='
                      <?php 
                      if(isset($_SESSION['preview_image_id']) && !empty($_SESSION['preview_image_id'])){
                          $ID = $_SESSION['preview_image_id'];
                          echo $this->basePath("img/image_uri/$ID.jpg");
                      } ?>'class="img-responsive"/></div>
                  <div class="col-md-6">
                      <h3><strong>Personal Mug</strong></h3>
                      <h3><small>Show your amazing coach just how great he is with this No.1 Coach Mug. This mug is a great gift for any occasion, make your gift extra special by personalising it with any name of your choice. This thoughtful gift is guaranteed to impress!</small></h3>
      
                      <div class="row top-buffer">
                          <div class="col-md-8">
      
                              <a id ="buttonSave" class="btn btn-success btn-lg btn-block">Save</a>
                              <a class="btn btn-success btn-lg btn-block" href="<?php echo $this->url('personal-mug', array('action'=>'add'));?>">Edit</a>
                          </div>
                      </div>
                      <div class="row top-buffer">
                          <ul>
                              <li>
                                  The mug has space for a maximum of 48 characters, over a maximum of 4 lines.
                              </li>
                              <li>
                                  Free Delivery when you spend over £40
                              </li>
                              <li>
                                  Guaranteed Fast, Secure Shipping
                              </li>
                          </ul>
                      </div>
      
                  </div>
              </div>
          </div>
      </div>
      <script>
          $('#buttonSave').click(function (){
                  var image_uri = $("#mug1").attr("src");
                  $.ajax({
                          type: 'POST',
                          dataType: 'json',
                          url: 'http://toxicfox.com/personal-mug/add',
                          async: false,
      
                          // you can use an object here
                          data: { image_uri: image_uri},
                          success: function(json) {
                              console.log(json.image_uri);
                          }
                      });
                  // you might need to do this, to prevent anchors from following
                  // or form controls from submitting
      
              });
      </script>
      

      控制器。

      namespace PersonalMug\Controller;
      
      use Zend\Mvc\Controller\AbstractActionController;
      use Zend\View\Model\ViewModel;
      use PersonalMug\Model\PersonalMug;          
      use PersonalMug\Form\PersonalMugForm;    
      
      
      class PersonalMugController extends AbstractActionController{
      protected $personalmugTable;
      
      public function getPersonalMugTable(){
          if(!$this->personalmugTable){
              $sm = $this->getServiceLocator();
              $this->personalmugTable = $sm->get('PersonalMug\Model\PersonalMugTable');
          }
          return $this->personalmugTable;
      }
      
      public function indexAction(){
          return new ViewModel(
              array(
                  'personalmugs' => $this->getPersonalMugTable()->fetchAll(),
              ));
      }
      public function addAction(){    
      
          $data['image_uri'] =  $this->getRequest()->getPost('image_uri');
          $personalmug = new PersonalMug();
          $personalmug->exchangeArray($data);
          $this->getPersonalMugTable()->save($personalmug);
          return $this->redirect()->toRoute('personal-mug');
      }
      public function previewAction(){
          if(isset($_POST['submit'])){
              session_start();
              $ID = uniqid();
              $_SESSION['preview_image_id'] = $ID;
              $text1 = htmlspecialchars($_POST['mugtext1']);
              $text2 = htmlspecialchars($_POST['mugtext2']);
              $text3 = htmlspecialchars($_POST['mugtext3']);
              $text4 = htmlspecialchars($_POST['mugtext4']);
              $this->getPersonalMugTable()->preview($ID,$text1,$text2,$text3,$text4);
          }
      }
      

      personalmug表文件。

      namespace PersonalMug\Model;
      
      use Zend\Db\TableGateway\TableGateway;
      use Zned\ServerUrl\Helper;
      
      class PersonalMugTable{
          protected $tableGateway;
      
          public function __construct(TableGateway $tableGateway){
              $this->tableGateway = $tableGateway;
          }
      
          public function fetchAll(){
              $resultSet = $this->tableGateway->select();
              return $resultSet;
          }
      
          public function getImage($image_id){
              $image_id  = (int) $image_id;
              $rowset = $this->tableGateway->select(array('image_id' => $image_id));
              $row = $rowset->current();
              if(!$row){
                  throw new \Exception("Could not find row $image_id");
              }
              return $row;
          }
      
          public function save(PersonalMug $personalmug){
              $data = array(
                  'image_id'  => $personalmug->image_id,
                  'image_uri'  => $personalmug->image_uri,
              );
      
              $image_id = (int) $personalmug->image_id;
              if($image_id == 0){
                  $this->tableGateway->insert($data);
              }else{
                  if($this->getImage($image_id)){
                      $this->tableGateway->update($data, array('image_id' => $image_id));
                  }else{
                      throw new \Exception('Mug id does not exist');
                  }
              }
          }
      
          public function deleteAlbum($image_id){
              $this->tableGateway->delete(array('image_id' => (int) $image_id));
          }
      
          public function preview($ID,$text1,$text2,$text3,$text4){
              strtoupper($text1);
              strtoupper($text2);
              strtoupper($text3);
              strtoupper($text4);
              // load the image from the file specified:
      
              $im = imagecreatefromjpeg('public/img/whitemug%20toxic%20fox.jpg');
              // if there's an error, stop processing the page:
              if(!$im){
                  die("");
              }
      
              // define some colours to use with the image
              $black = imagecolorallocate($im, 0, 0, 0);
      
      
              // now we want to write in the centre of the rectangle:
              $font ="public/fonts/arial.ttf"; // store the int ID of the system font we're using in $font
              // store the text we're going to write in $text
      
              // finally, write the string:
      
              imagettftext($im,60,0,260,460,$black,$font,$text1);
              imagettftext($im,60,0,260,560,$black,$font,$text2);
              imagettftext($im,60,0,260,660,$black,$font,$text3);
              imagettftext($im,60,0,260,760,$black,$font,$text4);
      
              imagejpeg($im, "public/img/image_uri/$ID.jpg");
      
              // tidy up
              imagedestroy($im);
          }
      }
      

1 个答案:

答案 0 :(得分:1)

我认为你的错误程度远低于框架。尝试查看Apache“error.log”以获取有关错误的更多详细信息。如果您发现任何问题,请告诉我。