如何使用ajax和php发送邮件

时间:2018-10-06 00:03:08

标签: php ajax

1

function save_val(){

    var leads = [];
    jQuery(".lead_src").each( function( indx, el ){
        var lead_src = jQuery(el).data('src');
        var is_checked = jQuery(el).is(':checked');

        if( is_checked ){
            leads.push(lead_src);
            // leads = [ "Phone Call", "Email"]
        }
    });

    var options = {};
    var options_selected = false;
    var options_sub_select = true;
    jQuery(".more-info").each(function(indx, el){
        var is_checked = jQuery(el).is(':checked');
        if( is_checked ){
            var option = jQuery(el).parent().find(".more-info-input").data("option");
            // 1 - dates, 2 - area
            var input_text = jQuery(el).parent().find(".more-info-input").val();
            // 1 - 22 sep, 2 - sandy beach
            options[option] = input_text;
            // 1- options = { dates : "22 sep" }, 2- options = { dates:"22 sep", area:"sandy beach"}
            if( input_text == "" ){
                options_sub_select = false;
            }
            options_selected = true;
        }
    });

    var long_term = jQuery("#long-term").is(":checked");

    var data = {
        options : options,
        leads : leads,
        long_term :
        long_term
    };

    if( leads.length>0 && ( (long_term && !options_selected)  ||
        (options_selected && options_sub_select) )  ){

            hide_error();

            data.user = jQuery("#username").val();
            data.pwd = jQuery("#pwd").val();

            jQuery.post( 'save.php', data, function(response){

            var data = jQuery.parseJSON(response);

            if( data.error ){
                //mostrar mensaje de error, intentelo de nuevo
                show_error("Error, please try again");          } else {
                // mostrar mensaje de exito
                jQuery("#container").html("<h3>THANK YOU FOR ANSWERING THE QUESTIONS</h3>");            }       });

        console.log("Ambas preguntas fueron respondidas", data);    } else
if( options_selected && !options_sub_select ) {         show_error("Please
answer all questions");     } else {        show_error("Both questions are
required");     } }

function show_error( error ){
    jQuery("#msg_error").html(error).show(); }

function hide_error(){  jQuery("#msg_error").hide(); }

function waiting(){     if( esperando_respuesta_ajax ){
        jQuery("#btn_login").val("Please wait...");     } else {
        jQuery("#btn_login").val("Login");  } }

function select_reason( el ){       var is_checked =
jQuery(el).is(":checked");

    if( is_checked ){
        jQuery(el).parent().children(".option-info").removeClass("hidden");
    } else {
        jQuery(el).parent().children(".option-info").addClass("hidden");
    } }

0 个答案:

没有答案