简体   繁体   中英

Undefined index for get variable

I have a div with the class .excelDL . OnClick of the div I am submitting a form using AJAX, without refreshing the page, which seems to work fine.

The problem I am having is I need to detect if $_GET['excel'] has been set to one after the form is submitted, in my mail.php script and I am getting an undefined index error. I started getting an undefined index error after I added the submit trigger.

I am new to ajax, I was wondering if someone can help me fix this undefined index problem.

The reason I need a trigger for my form is because all the $_POST values from the form are going to be in the excel file that will be created.

Many thanks in advance

mail.php

if($_GET['excel']==1){
    echo '<h1>hello</h1>';
}

AJAX

           $('.excelDL').click(function(){
                $('#myForm').trigger('submit', function(e){
                    $.post('mail.php?excel=1', $(this).serialize(), function (data) {
                    //SUCCESS
                    $('.successORfail').html(data);
                        setTimeout(function(){
                            $(".successORfail").fadeOut("slow", function () {
                                $(".successORfail").empty().show();
                            });
                        }, 4500);
                    }).error(function() {
                        alert("Fatal Error: mail.php not found!");
                    });
                    e.preventDefault();
                });         
            });

Don't issue an HTTP POST but use HTTP GET instead. Also don't put the parameter in the request URL but rather in the arguments.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM