English 中文(简体)
页: 1 使用ja子和(或)att子时的成绩
原标题:jQuery issues when using ajax and .attr( class , new_class )

我正在使用泽德框架,以说明我为这一职位增添了“拯救行动”的工作,而且它的工作是徒劳的。 它将像我所希望的那样,改变和改变这一类别。 功能上载,只是修改案文,无视 j。 我确实可以提醒说,工作不可行。 我错误地说,美元没有定义。 如何在1起案件中加以界定?

我正在用麻风机赶上上上上载荷,只是把它扔进了光灯。

我希望能找到解决办法,这似乎在某个地方是一个小问题,但我无法自己找到。 谢谢。

它希望:

$(document).ready(function() {
  $( #newsForm ).ajaxForm({
    target:  #savecontainer 
  });
  $( #uploadForm ).ajaxForm({
    target:  #savecontainer 
  });
  $("#btn_save").click(function () {
    $( #newsForm ).submit();
  });
  $("#btn_upload").click(function () {
    $( #uploadForm ).submit();
  });
});


public function saveAction()
{ 
  $this->_helper->layout->disableLayout();
  $db = new Admin_Model_DbAccess();
  if(isset($_POST[ active ]))
    $_POST[ active ] = 1;
  else 
    $_POST[ active ] = 0;

  if($_POST[ id ] == 0){
    // If it is a new post

    $data = array(
       header  => $_POST[ header ],
       message  => $_POST[ message ],
       date  => time(),
       user  => Zend_Auth::getInstance()->getStorage()->read()->id,
       image  => $_POST[ image ],
       active  => $_POST[ active ],
       category  => $_POST[ category ]
    );
    if($db->addNews($data)){
      // set the css variables to saved
      echo "<script type= text/javascript >
        $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_success ).fadeIn(400);
        $( #news_id ).attr( value ,  ".$db->lastInsertId()." );
    $( #upload_box ).show( slide , {direction:  up }, 500);
    $( #news_id_upload ).attr( value ,  ".$db->lastInsertId()." );
      </script>";
      echo "Status: Added.";
    }else{
      // set the css variables to failed
      echo "<script type= text/javascript >
        $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_fail ).fadeIn(400);
      </script>";
      echo "Status: Error.";
    }
  }else{
    $data = array(
       header  => $_POST[ header ],
       message  => $_POST[ message ],
       image  => $_POST[ image ],
       active  => $_POST[ active ],
       category  => $_POST[ category ]
    );
    $db = new Admin_Model_DbAccess();
    if($db->updateNews($_POST[ id ], $data)){
      // set the css variables to saved
      echo "<script type= text/javascript >
        $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_success ).fadeIn(400);
      </script>";
      echo "Status: Updated.";
    }else{
      // set the css variables to failed
      echo "<script type= text/javascript >
        $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_fail ).fadeIn(400);
      </script>";
      echo "Status: Error.";
    }
  }
}
public function uploadAction(){
  $this->_helper->layout->disableLayout();

  if ($this->_request->isPost()) {
    //Startup the adapter to upload
      $adapter = new Zend_File_Transfer_Adapter_Http();
  //Define the upload path
       define( UPLOAD_NEWS_IMAGE_PATH , APPLICATION_PUBLIC_PATH. "/img/news/");
   // Fixa upload path
      $adapter->addValidator( Extension , false, array( jpg ,  jpeg  ,  gif  ,  png ))
      ->addValidator( Count , false , array(  min  => 0,  max  => 0));

  $file = $adapter->getFileInfo();

  $adapter->receive();
  $messages = $adapter->getMessages();
  if(isset($messages[ fileCountTooMany ]) && !isset($messages[ fileExtensionFalse ])){
    //If the file does exists (Everything went fine);
    $fileinfo[ ext ] = end(explode(".", $file[ upload_0_ ][ name ]));
    $uploaded_filename = $_POST[ id ].".".$fileinfo[ ext ];
    // Change name to id.jpg for example
    move_uploaded_file($file[ upload_0_ ][ tmp_name ], UPLOAD_NEWS_IMAGE_PATH.$uploaded_filename);
    // resize to 
    $full_thumb = Butikadmin_Model_PhpThumbFactory::create(UPLOAD_NEWS_IMAGE_PATH.$uploaded_filename);
    $full_thumb->resize(960, 500);
    $id = $_GET[ id ];
    if($full_thumb->save(UPLOAD_NEWS_IMAGE_PATH.$uploaded_filename)){
        // set the css variables to saved
        echo "<script type= text/javascript >
          $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_success ).fadeIn(400);
          $( #upload_box ).fadeOut(500);
        </script>";
        echo "Status: Uploaded.";
    }
  }else{
    // If the file is not right format
    // set the css variables to saved
      echo "<script type= text/javascript >
          $( #savecontainer ).fadeOut(200).attr( class ,  savecontainer_fail ).fadeIn(400);
        </script>";
      echo "Status: Error.";
  }
  }
}
问题回答

why not using an ajax call instead of .submit? and in the php code, remove the js record and return data (array or ojbect) from the function and handle it back in the js script with a callback function which return that data





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签