2012-08-29 65 views
0

ajaxForm突然停止工作。我製作了一個圖片上傳的表格,並使用ajaxForm將其提交給一個php頁面。它工作了,我繼續休息。現在我已經編輯了一個功能,我發現ajaxForm不再提交。ajaxForm突然不提交

我花了幾個小時尋找和調試,但我沒有看到任何錯誤。

全部Ajax代碼:

    <SCRIPT type="TEXT/JAVASCRIPT" src="http://code.jquery.com/jquery-latest.js"></SCRIPT> 
       <SCRIPT type="TEXT/JAVASCRIPT" src="http://malsup.github.com/jquery.form.js"></SCRIPT> 
       <SCRIPT type="TEXT/JAVASCRIPT">     
       function edit_product(btn_id, edit_type) { 
       var ajaxRequest; 

        try { 
         //opera 8.0+, firefox, safari.. 
         ajaxRequest = new XMLHttpRequest(); 
         } 
         catch (e){ 
         // internet explorer browsers 
         try { 
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
          } 
          catch (e) { 
           try { 
           ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            catch (e) { 
             //something went wrong 
             alert("Your browser doesn't support ajax, which is needed for our website functionality. Please update your browser or install a new browser"); 
             return false; 
               } 
             } 
           } 
       ajaxRequest.onreadystatechange = function() { 
       if(ajaxRequest.readyState == 4) { 
       $('#DIV_MODIFY_PRODUCT').empty(); 
       $('#DIV_MODIFY_PRODUCT').slideToggle(250); 
       var ajaxDisplay = document.getElementById('DIV_MODIFY_PRODUCT'); 
       ajaxDisplay.innerHTML = ajaxRequest.responseText; 
               } 
                  } 
       var e_id = btn_id; 
       var e_type = edit_type; 
       var get_string = "?search="+e_id+"&type="+e_type; 

       ajaxRequest.open("GET", "elcoma_edit_product.php" + get_string, true); 
       ajaxRequest.send(null); 
       } 

       function search_emails() { 
       var ajaxRequest; 

        try { 
         //opera 8.0+, firefox, safari.. 
         ajaxRequest = new XMLHttpRequest(); 
         } 
         catch (e){ 
         // internet explorer browsers 
         try { 
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
          } 
          catch (e) { 
           try { 
           ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            catch (e) { 
             //something went wrong 
             alert("Your browser doesn't support ajax, which is needed for our website functionality. Please update your browser or install a new browser"); 
             return false; 
               } 
             } 
           } 
       ajaxRequest.onreadystatechange = function() { 
       if(ajaxRequest.readyState == 4) { 
       var ajaxDisplay = document.getElementById('EMAIL_SEARCH_DIV_RESULTS'); 
       ajaxDisplay.innerHTML = ajaxRequest.responseText; 
               } 
                  } 
        var e_name = document.getElementById('E_SEARCHBAR').value; 
        var e_option = document.getElementById('E_SEARCH_SELECT').value; 
        var get_string = "?search="+e_name+"&option="+e_option; 

       ajaxRequest.open("GET", "elcoma_check_emails.php" + get_string, true); 
       ajaxRequest.send(null); 
       } 
       </SCRIPT> 
       <SCRIPT type="TEXT/JAVASCRIPT"> 
       function search_product() { 
       var ajaxRequest; 

        try { 
         //opera 8.0+, firefox, safari.. 
         ajaxRequest = new XMLHttpRequest(); 
         } 
         catch (e){ 
         // internet explorer browsers 
         try { 
          ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
          } 
          catch (e) { 
           try { 
           ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
            } 
            catch (e) { 
             //something went wrong 
             alert("Your browser doesn't support ajax, which is needed for our website functionality. Please update your browser or install a new browser"); 
             return false; 
               } 
             } 
           } 
       ajaxRequest.onreadystatechange = function() { 
       if(ajaxRequest.readyState == 4) { 
       var ajaxDisplay = document.getElementById('P_SEARCH_DIV_RESULTS'); 
       ajaxDisplay.innerHTML = ajaxRequest.responseText; 
               } 
                  } 
        var p_name = document.getElementById('P_SEARCHBAR').value; 
        var p_option = document.getElementById('P_SEARCH_SELECT').value; 
        var get_string = "?search="+p_name+"&option="+p_option; 

       ajaxRequest.open("GET", "elcoma_search_product.php" + get_string, true); 
       ajaxRequest.send(null); 
       } 
       </SCRIPT> 
       <SCRIPT type="TEXT/JAVASCRIPT"> 
        $(document).ready(function() { 

        $('#nav LI').hover(
        function() { 
        //show its submenu 
        $('UL', this).stop().slideDown(200); 

        }, 
        function() { 
         //hide its submenu 
         $('UL', this).stop().slideUp(200);   
        } 
        ); 

        $('A#ID_NEW_PROJECT').click(function() { 
        $('#DIV_NEW_PROJECT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_SRCH_PROJECT').click(function() { 
        $('#DIV_SRCH_PROJECT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_NEW_CONTACT').click(function() { 
        $('#DIV_NEW_CONTACT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_SRCH_CONTACT').click(function() { 
        $('#DIV_SRCH_CONTACT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_NEW_PRODUCT').click(function() { 
        $('#DIV_NEW_PRODUCT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_SRCH_PRODUCT').click(function() { 
        $('#DIV_SRCH_PRODUCT').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_CALCULATOR').click(function() { 
        $('#DIV_CALCULATOR').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_CONVERTER').click(function() { 
        $('#DIV_CONVERTER').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_REMINDER').click(function() { 
        $('#DIV_REMINDER').slideToggle(250); 

        return false; 
        }); 

        $('A#ID_EMAIL').click(function() { 
        $('#DIV_CHECK_EMAIL').slideToggle(250); 

        return false; 
        }); 

        $('#SAVE_NEW_PRODUCT').click(function() { 
         $('#NEW_PROJECT_FORM').ajaxForm(
          { 
          target: '#MAIN_IMAGE_PREVIEW' 
          }).submit(); 
        }); 

        $('#SAVE_NEW_CONTACT').click(function() { 
         $('#NEW_CONTACT_FORM').ajaxForm(
          { 
          target: '#CONTACT_PREVIEW' 
          }).submit(); 
        }); 


        $(document).on("click", '#SAVE_EDIT_PRODUCT', function(event) { 
         $('#EDIT_PROJECT_FORM').ajaxForm(
          { 
          beforeSubmit: function() { 
          $('#MAIN_EDIT_DIV').empty(); 
          }, 
          target: '#EDIT_MAIN_IMAGE_PREVIEW' 
          }).submit(); 
        }); 
        }); 
       </SCRIPT> 

只給ajaxForm提交PART:

     $('#SAVE_NEW_PRODUCT').click(function() { 
         $('#NEW_PROJECT_FORM').ajaxForm(
          { 
          target: '#MAIN_IMAGE_PREVIEW' 
          }).submit(); 
        }); 

表單代碼:

<DIV ID="DIV_NEW_PRODUCT" CLASS="CONTENT_DIV"> 
        <FORM ID="NEW_PROJECT_FORM" METHOD="POST" ACTION="elcoma_new_product.php" ENCTYPE="MULTIPART/FORM-DATA"> 
        <FIELDSET> 
        <LABEL CLASS="NORMAL_LABEL" STYLE="COLOR: DARKBLUE">NEW PRODUCT</LABEL> 
        <BR> 
        <DIV ID="MAIN_IMAGE_PREVIEW"></DIV> 
        <DIV ID="GAL1_IMAGE_PREVIEW"></DIV> 
        <DIV ID="GAL2_IMAGE_PREVIEW"></DIV> 
          <HR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_NAME">NAME</LABEL> 
          <INPUT TYPE="TEXT" ID="P_NAME" NAME="P_NAME"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_NAME_ERROR" STYLE=" COLOR: RED" > 
          (!) PRODUCT NAME MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_TYPE">TYPE</LABEL> 
          <INPUT TYPE="TEXT" ID="P_TYPE" NAME="P_TYPE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_TYPE_ERROR" STYLE=" COLOR: RED" > 
          (!) PRODUCT TYPE MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_MANUFACTURER">MANUFACTURER</LABEL> 
          <INPUT TYPE="TEXT" ID="P_MANUFACTURER" NAME="P_MANUFACTURER"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_MANUFACTURER_ERROR" STYLE=" COLOR: RED" > 
          (!) MANUFACTURER NAME MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_QUANTITY">QUANTITY</LABEL> 
          <INPUT TYPE="TEXT" ID="P_QUANTITY" NAME="P_QUANTITY"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_QUANTITY_ERROR" STYLE=" COLOR: RED" > 
          (!) QUANTITY MISSING 
          </LABEL>   
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_BIG_PRICE">PRICE-WHOLESALE</LABEL> 
          <INPUT TYPE="TEXT" ID="P_BIG_PRICE" NAME="P_BIG_PRICE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_BIG_PRICE_ERROR" STYLE=" COLOR: RED" > 
          (!) PRICE-WHOLESALE MISSING 
          </LABEL>   
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_SINGLE_PRICE">PRICE-SINGLE</LABEL> 
          <INPUT TYPE="TEXT" ID="P_SINGLE_PRICE" NAME="P_SINGLE_PRICE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_SINGLE_PRICE_ERROR" STYLE=" COLOR: RED" > 
          (!) PRICE-SINGLE MISSING 
          </LABEL>   
          <BR> 
          <HR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_DESC_EN">DESCRIPTION-EN</LABEL> 
          <TEXTAREA ID="P_DESC_EN" NAME="P_DESC_EN" COL="15" ROWS="10"></TEXTAREA> 
          <LABEL CLASS="ERROR_LABEL" ID="P_DESC_EN_ERROR" STYLE=" COLOR: RED" > 
          (!) DESCRIPTION-EN MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_DESC_MK">DESCRIPTION-MK</LABEL> 
          <TEXTAREA ID="P_DESC_MK" NAME="P_DESC_MK" COL="15" ROWS="10"></TEXTAREA> 
          <LABEL CLASS="ERROR_LABEL" ID="P_DESC_MK_ERROR" STYLE=" COLOR: RED" > 
          (!) DESCRIPTION-MK MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_SHORT_DESC_EN">SHORT DESC-EN</LABEL> 
          <TEXTAREA ID="P_SHORT_DESC_EN" NAME="P_SHORT_DESC_EN" COL="5" ROWS="5"></TEXTAREA> 
          <LABEL CLASS="ERROR_LABEL" ID="P_SHORT_DESC_EN_ERROR" STYLE=" COLOR: RED" > 
          (!) SHORT DESC-EN MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_SHORT_DESC_MK">SHORT DESC-MK</LABEL> 
          <TEXTAREA ID="P_SHORT_DESC_MK" NAME="P_SHORT_DESC_MK" COL="5" ROWS="5"></TEXTAREA> 
          <LABEL CLASS="ERROR_LABEL" ID="P_SHORT_DESC_MK_ERROR" STYLE=" COLOR: RED" > 
          (!) SHORT DESC-MK MISSING 
          </LABEL> 
          <HR> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_MAIN_IMAGE">MAIN IMAGE</LABEL> 
          <INPUT TYPE="FILE" ID="P_MAIN_IMAGE" NAME="P_MAIN_IMAGE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_MAIN_IMAGE_ERROR" STYLE=" COLOR: RED" > 
          (!) MAIN IMAGE MISSING 
          </LABEL> 
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_GAL1_IMAGE">GALLERY IMAGE-1</LABEL> 
          <INPUT TYPE="FILE" ID="P_GAL1_IMAGE" NAME="P_GAL1_IMAGE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_GAL1_IMAGE_ERROR" STYLE=" COLOR: RED" > 
          (!) GALLERY IMAGE 1 MISSING 
          </LABEL>  
          <BR> 
          <LABEL CLASS="NORMAL_LABEL" FOR="P_GAL2_IMAGE">GALLERY IMAGE-2</LABEL> 
          <INPUT TYPE="FILE" ID="P_GAL2_IMAGE" NAME="P_GAL2_IMAGE"> 
          <LABEL CLASS="ERROR_LABEL" ID="P_GAL2_IMAGE_ERROR" STYLE=" COLOR: RED" > 
          (!) GALLERY IMAGE 2 MISSING 
          </LABEL> 
          <BR> 
          <HR> 
          <INPUT TYPE="BUTTON" NAME="NEW_PRODUCT_COPY" ID="COPY_NEW_PRODUCT" VALUE="Copy Last" CLASS="FORM_BUTTONS"> 
          <INPUT TYPE="BUTTON" NAME="NEW_PRODUCT_RESET" ID="RESET_NEW_PRODUCT" VALUE="Reset" CLASS="FORM_BUTTONS"> 
          <INPUT TYPE="BUTTON" NAME="NEW_PRODUCT_SAVE" ID="SAVE_NEW_PRODUCT" VALUE="Save" CLASS="FORM_BUTTONS"> 
        </FIELDSET> 
        </FORM> 
       </DIV> 

php文件:

    <?php 
      $path = "products/"; 
     $temp = $_FILES['P_MAIN_IMAGE']['tmp_name']; 
     $name = $_FILES['P_MAIN_IMAGE']['name']; 
     $temp_gal1 = $_FILES['P_GAL1_IMAGE']['tmp_name']; 
     $name_gal1 = $_FILES['P_GAL1_IMAGE']['name']; 
     $temp_gal2 = $_FILES['P_GAL2_IMAGE']['tmp_name']; 
     $name_gal2 = $_FILES['P_GAL2_IMAGE']['name']; 

     $p_name = ($_POST['P_NAME']); 
     $p_type = ($_POST['P_TYPE']); 
     $p_manu = ($_POST['P_MANUFACTURER']); 
     $p_quant = ($_POST['P_QUANTITY']); 
     $price_plural = ($_POST['P_BIG_PRICE']); 
     $price_single = ($_POST['P_SINGLE_PRICE']); 

     $long_desc_en = ($_POST['P_DESC_EN']); 
     $long_desc_mk = ($_POST['P_DESC_MK']); 
     $short_desc_en = ($_POST['P_SHORT_DESC_EN']); 
     $short_desc_mk = ($_POST['P_SHORT_DESC_MK']); 

     move_uploaded_file($temp, $path.$name); 
     move_uploaded_file($temp_gal1, $path.$name_gal1); 
     move_uploaded_file($temp_gal2, $path.$name_gal2); 
     echo "<img src='products/".$name."' class='MAIN_IMAGE_PREVIEW' width='150px' height='150px'><BR>"; 
     echo "<img src='products/".$name_gal1."' class='GAL1_IMAGE_PREVIEW' width='150px' height='150px'><BR>"; 
     echo "<img src='products/".$name_gal2."' class='GAL2_IMAGE_PREVIEW' width='150px' height='150px'><BR>"; 
     echo "<LABEL STYLE='COLOR: DARKGREEN'>New product successfully saved! Name: ".$p_name."</LABEL>"; 

$pattern = "/[^[email protected]]/"; 
$pattern2 = "/[^0-9.]/"; 
$pattern3 = "/[^a-zA-Z]/"; 
$replace = " "; 
$replace2 = ""; 

$clean_name = preg_replace($pattern, $replace2, $p_name); 
$clean_manufacturer = preg_replace($pattern, $replace2, $p_manu); 
$clean_wholesale = preg_replace($pattern2, $replace2, $price_plural); 
$clean_retail = preg_replace($pattern2, $replace2, $price_single); 
$clean_quantity = preg_replace($pattern2, $replace2, $p_quant); 
$clean_type = preg_replace($pattern3, $replace2, $p_type); 

mysql_connect("localhost", "root", "") or die(mysql_error()); 
mysql_select_db("elcomass") or die(mysql_error()); 
$result = mysql_query("INSERT INTO alpha_p_main 
(alpha_p_name_en, alpha_p_long_desc_en, alpha_p_long_desc_mkd, alpha_p_short_desc_en,   alpha_p_short_desc_mkd, alpha_p_firm_owner, alpha_p_imglink_main, alpha_p_imglink_gal1, alpha_p_imglink_gal2, alpha_p_search_d_for, alpha_p_search_d_cont, alpha_p_quantity, alpha_p_price_retail, alpha_p_price_wholesale, alpha_p_type 
) VALUES 
('$clean_name', '$clean_long_desc_en', '$clean_long_desc_mk', '$clean_short_desc_en', '$clean_short_desc_mk', '$clean_manufacturer', '$name', '$name_gal1', '$name_gal2', '0', '0', '$clean_quantity', '$clean_retail', '$clean_wholesale', '$clean_type')"); 
if(!$result) 
{ 
echo "Error! ".mysql_error(); 
} 
?> 

回答

0

您的問題不是您的發佈代碼。它工作正常。必須與您的目標.php文件有關。

+0

即使在查詢本身開始工作之前,當我點擊保存按鈕時,php頁面應該回顯上傳類型的圖片。但是現在,該按鈕在點擊時不做任何事我會張貼PHP頁面,但我懷疑錯誤是否有 –

+0

仍然適用於我。對不起;)你正在一臺服務器上測試一切?只是爲了排除Cors問題。 – lexith

+0

該死的。我真的不知道我對代碼做了什麼,但表單沒有提交(只是嘗試了一個警告框,這是可行的,所以按鈕點擊確定) - 是在一臺服務器上。你用ajaxForm進行測試嗎? –

0

我現在就去拍自己的膝蓋。 我忘記了</form>結束標記。