0

我有这个 javascript 代码,我不使用 PHP,当我尝试提交表单时,对象(“数据”)是未定义的。我尝试了很多更改,但是使用此配置,表单已发送,但响应未定义...

$(this).html('<div id="contactable_inner"></div><form id="contactForm" class="contactForm" method="post" onSubmit="return false;">'
                    + '<p><label for="id">' + options.id + '</label><input id="id" class="contact_id" name="id" value="" disabled="disabled"/>'
                    + '<p><label for="name">' + options.name + '</label><input id="name" class="contact" name="name"/>'
                    + '<p><label for="select">' + options.select + '</label><select id="select" class="select" name="select">'
                    + '<option value="error">Error</option>'
                    + '<option value="consulta">Consulta</option>'
                    + '<option value="sugerencia">Sugerencia</option>'
                    + '<option value="aviso">Aviso</option>'
                    + '<option value="otro">Otro</option></select>'
                    + '<p><label for="phone">' + options.phone + '</label><input id="phone" class="contact" name="phone"/>'
                    + '<p><label for="email">' + options.email + '</label><input id="email" class="contact" name="email" />'
                    + '<p><label for="message">' + options.message + '</label><textarea id="message" name="message" class="message" rows="4" cols="30" ></textarea>'
                    + '<p><input class="submit" id="enviar" type="submit" onclick="return validateForm();" value="' + options.submitButton +'"/><input id="cancelar" class="button" type="button" onclick="closeDialog()" value="'+ options.cancelButton
                    + '"/></p></form>'
                );

    if(enviaEmail == true)
    {
        try
        {
            $("#contactForm").submit(function() 
            {
                $.ajax(
                {
                    type: "POST",
                    url: options.url,
                    cache: false,
                    crossDomain: true,
                    dataType: "script",
                    async: false,
                    jsonp: false,
                    timeout: 3000,
                    data : 
                    {
                        accion: 'setNotificacion',
                        idUsuario : $(this_id_prefix+ '#id').val(),
                        nomUsuario : $(this_id_prefix+ '#name').val(),
                        tlfUser : $(this_id_prefix+ '#phone').val(),
                        eMailUser : $(this_id_prefix+ '#email').val(),
                        tipoCons : $(this_id_prefix+ '#select').val(),
                        textoCons : $(this_id_prefix+ '#message').val(),
                        dirMailInci : options.dirIncidencias,
                        servidorCorreo : options.servidorSMTP,
                        fromDelMail : options.fromMail,
                        nomAplicacion : options.nombreAplicacion,
                    }
                })
                .done(function(data) 
                {
                    console.log(data);
                    if(data == "true")
                    {
                        alert('Notificación enviada satisfactoriamente.');
                        closeDialog();
                    }
                    else
                    {
                        alert('Error enviando los datos al servicio. Puede que algún parámetro sea incorrecto.');
                    }
                })
                .fail(function(jqXHR, textStatus) 
                {
                    alert('Error enviando los datos al servicio. El servicio no está disponible en estos momentos.'+textStatus);
                });
            });
        }
        catch(err)
        {
            txt="There was an error on this page.\n\n";
            txt+="Error description: " + err.message + "\n\n";
            txt+="Click OK to continue.\n\n";
            alert(txt);
        }

有什么建议吗??谢谢

4

0 回答 0