Всем привет!
Подскажите, что делает этот код, и как его применить в форме?
<script type="text/javascript">
jQuery(function(e) {
var $ = jQuery;
$('.register-form').parent().attr('id', 'cm-signup-form-container').attr('class','');
$.ajax({
url: 'https://staging.go.com/users/new_signup',
crossDomain: true,
success: function(data, textStatus, jqXHR) {
$('#cm-signup-form-container').html(data);
$('#cm-signup-form-container').find('#signup-form').submit(function(e) {
e.preventDefault();
$.ajax({
url: 'https://staging.go.com/users/create_signup',
crossDomain: true,
type: "POST",
dataType: "json",
data: $(this).serialize(),
success: function(data, textStatus, jqXHR) {
if (data['status'] == "success") {
// TODO: Trigger google analytics event here
var customer_email = data.user.email;
var customer_firstname = data.user.firstname;
var customer_lastname = data.user.lastname;
console.log("[TODO] Trigger GAnalytics event here using: ", customer_email, customer_firstname, customer_lastname);
// FIXME: Change this to the URL you want to redirect the user to after success
console.log("[FIXME] Implement redirecting user after success");
// window.location = "/install";
} else {
var error_message = "<div>Your signup failed!</div>";
if (data.errors) {
error_message = "<ul>";
for (var i = 0; i < data.errors.length; i++) {
error_message += "<li>" + data.errors[i] + "</li>";
};
error_message += "</ul>";
} else {
error_message = "<div>Please contact support for assistance.</div>";
}
$("#signup-form-errors").html(error_message);
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Something went wrong.");
}
});
});
},
error: function(jqXHR, textStatus, errorThrown) {
console.error("Failed to load remote form");
}
});
});
</script>
<!--
=====================================================
Example output injected into this div:
$('#signup-form-errors')
=====================================================
-->
<ul>
<li>Email has already been taken</li>
<li>Email is already being used. Please choose another.</li>
</ul>
Спасибо!