0
A
cevap
0
sadece çok gibi normal bir işlev tanımlamak Can not yerine csrfSafeMethod
+1
gerekir. 'beforeSend' (veya" ajaxSetup "ın içindeki herhangi bir yöntem)" seçenekler "e ayarlanan içerikle çağrılmaz. –
3
ait this.csrfSafeMethod
deneyin:
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
1
Neden? Yönteminiz, beforeSend
'da başvurmadığınız bir nesneye eklendiğinden. Temelde böyle hayal edebilirsiniz:
$.ajaxSetup = function(options) {
var beforeSend = options.beforeSend;
// do stuff...
var xhr = getXHR();
var settings = getSettings();
beforeSend(xhr, settings);
};
$.ajaxSetup({
csrfSafeMethod: function() { ... },
beforeSend: function() {
// `this` is the same as if I called this function in the global scope
// It has no reference to the `options` object
}
});
kaynak kodunda gerçek kod şuna benzer:
s
// Allow custom headers/mimetypes and early abort
if (s.beforeSend &&
(s.beforeSend.call(callbackContext, jqXHR, s) === false || completed)) {
// Abort if not done already and return
return jqXHR.abort();
}
herhangi mevcut kapsamda, bazı jQuery nesnesidir.
Bunu nasıl düzelteceğinize ilişkin olarak, işlevinizi başka bir yerde bildirmeniz veya seçeneklerinizi başvurulan bir nesneye atamanız gerekir.
var options = {
csrfSafeMethod: function(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
},
beforeSend: function(xhr, settings) {
if (!options.csrfSafeMethod(settings.type) && !this.crossDomain) {
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
};
İlgili konular
- 1. Ajax çağrı
- 2. Ajax https çağrı?
- 3. Yöntem çağrı URL parametreleri Açısal JS var ben aşağıdaki ihtiyacı
- 4. dosya yükleme ajax çağrı
- 5. Jsp ajax çağrı jquery kullanarak
- 6. Çağrı()
- 7. Çağrı
- 8. codeception - acking çağrı çağrı verileri
- 9. Ekran 'yükleme' görüntü AJAX çağrı devam
- 10. C++ yöntem çağrı dağıtıcısı oluşturmak mümkün mü?
- 11. jQuery/AJAX bir zamanlayıcı ile çağrı
- 12. Çağrı fnGetData() Böyle bir çağrı yapmaya çalışıyorum
- 13. JavaScript kullanarak yöntem çağrı bağımsız değişkenlerini durdurun
- 14. sharepoint ajax çağrı internet explorer'da gösterilmiyor
- 15. Ajax Üzerindeki Nesnenin Dizisini Alın Çağrı başarısı
- 16. $ .ajax garip atıyor "Unheught TypeError: Yasadışı çağrı"
- 17. ajax çağrı başarısı ancak hiçbir veri döndürülmedi
- 18. AJAX çağrı Kısmi render to Rails 3
- 19. Ajax çağrı Yani burada Yii çerçevesini
- 20. Ajax çağrı J3 MVC3 denetleyicisinden almak için
- 21. undefined yöntemine çağrı DateTime :: php'de yöntem ekle
- 22. WordPress Ajax Çağrı - WordPress Kullanıcı Kimliği
- 23. JQuery kullanarak ASP.NET ajax çağrı listesine ekler
- 24. Çağrı fonksiyonu
- 25. Çağrı yığını
- 26. IllegalArgumentException: Çağrı
- 27. Muğlak Çağrı
- 28. Tekrarlayıcıda çağrı
- 29. Erişim ASP.NET denetimi statik [WebMethod] (JS ajax çağrı)
- 30. Ben hızlı şekilde şöyle var Çağrı
Bil diye söylüyorum, (en azından) GET istekleri ** DO ** çalışmaz CSRF koruması – christophetd