2017-09-23 5 views
-1

Wie kann ich Lade-Symbol oder drehen, während meine während Ajax Anruf. unten ist mein CodeWie lade ich das Symbol auf sweetalert

swal({ 
     title: "Confirm your transaction", 
     html:true, 
     showSpinner: true, 
     showCancelButton: true, 
     confirmButtonColor: "#DD6B55", 
     confirmButtonText: "Send", 
     closeOnConfirm: false 
    },function() { 
     $.ajax({ 
    type: "post", 
    url: remoteUrl, 
    data: largeParams, 
    success: function (data) { } 
    }).done(function (data) { 
    swal("Thank you for your order", data, "success"); 
    }).error(function (data) { 
    swal("Oops", "We couldn't connect to the server!", "error"); 
}); 
}); 

Antworten werden geschätzt.

+0

Ich habe noch nie SweetAlert benutzt, aber die Webseite überprüft (https://sweetalert.js.org) Ich kann nicht alle Methoden finden: html, showSpinner, showCancelButton, confirmButtonColor, confirmButtonText, closeOnConfirm ... Sind Sie mit diesem Plugin oder gibt es ein anderes? –

+0

mit Versprechen 'https: // sweetalert.js.org/guides/# using-Versprechen' – tonoslfx

Antwort

0

Verwenden Sie die Versprechen, diese Code-Referenz von der Website.

https://sweetalert.js.org/guides/#ajax-requests

swal({ 
    text: 'Search for a movie. e.g. "La La Land".', 
    content: "input", 
    button: { 
    text: "Search!", 
    closeModal: false, 
    }, 
}) 
.then(name => { 
    if (!name) throw null; 

    return fetch(`https://itunes.apple.com/search?term=${name}&entity=movie`); 
}) 
.then(results => { 
    return results.json(); 
}) 
.then(json => { 
    const movie = json.results[0]; 

    if (!movie) { 
    return swal("No movie was found!"); 
    } 

    const name = movie.trackName; 
    const imageURL = movie.artworkUrl100; 

    swal({ 
    title: "Top result:", 
    text: name, 
    icon: imageURL, 
    }); 
}) 
.catch(err => { 
    if (err) { 
    swal("Oh noes!", "The AJAX request failed!", "error"); 
    } else { 
    swal.stopLoading(); 
    swal.close(); 
    } 
}); 
0

Vom GitHub doc:

swal({ 
 
    title: "Ajax request example", 
 
    text: "Submit to run ajax request", 
 
    type: "info", 
 
    showCancelButton: true, 
 
    closeOnConfirm: false, 
 
    showLoaderOnConfirm: true 
 
}, function() { 
 
    setTimeout(function() { 
 
    swal("Ajax request finished!"); 
 
    }, 2000); 
 
});

ich das versucht habe und einwandfrei funktioniert, ersetzen Sie einfach die setTimeout-Funktion mit Ihrer Ajax-Request.