ajaxForm 突然不提交



ajaxForm突然停止工作。我制作了一个上传图像的表单,并使用ajaxForm将其提交到php页面。它起了作用,我继续做剩下的。现在我已经做了编辑功能,我发现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提交部分:

                        $('#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 = "/[^a-zA-Z0-9-.@]/";
$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();
}
?>

问题不在于发布的代码。它运行良好。必须与您的目标.php文件有关。

我现在就去射中自己的膝盖。我忘记了一个</form>结束标记。

相关内容

  • 没有找到相关文章

最新更新