Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [JavaScript]Ajax. Przypisanie zwróconej przez ajax wartości polu obiektu.
koszykarze
post
Post #1





Grupa: Zarejestrowani
Postów: 119
Pomógł: 0
Dołączył: 10.10.2015
Skąd: Warszawa

Ostrzeżenie: (0%)
-----


Chcę przypisać zwrócona przez ajax wartość polu obiektu js.
taki kod mam:
  1. $(document).ready(function () {
  2. {% if sessionCart is empty %}
  3. var sessionCart = [];
  4. {% else %}
  5. var sessionCart = {{ sessionCart|raw }};
  6. {% endif %}
  7.  
  8. var cart = kendo.observable({
  9. contents: sessionCart,
  10.  
  11. updateSessionCart: function () {
  12. $.ajax({
  13. type: 'POST',
  14. url: '{{ path('session_cart_update') }}',
  15. dataType: 'json',
  16. data: {'cart': JSON.stringify(this.contents)},
  17. });
  18. },
  19.  
  20. getSessionCart: function () {
  21. $.ajax({
  22. type: 'GET',
  23. url: '{{ path('get_session_cart') }}',
  24. dataType: 'json',
  25. success: function (data) {
  26. this.contents = data;
  27. },
  28. });
  29. },
  30.  
  31. add: function (item) {
  32. this.getSessionCart();
  33. console.log('this.contents ' + JSON.stringify(this.contents));//TU WARTOŚĆ JEST STARA
  34. }


Problem polega na tym że console.log z ostatniego wiersza zwraca starą wartość, nie nową.
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 14:53