Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [ajax] tablice do php
blokern
post
Post #1





Grupa: Zarejestrowani
Postów: 107
Pomógł: 0
Dołączył: 27.02.2008

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


hej mam taki obiekt
  1. [
  2. {
  3. "id": "3",
  4. "name": "in_1",
  5. "value": "25"
  6. },
  7. {
  8. "id": "10",
  9. "name": "in_1",
  10. "value": "25"
  11. },
  12. {
  13. "id": "15",
  14. "name": "in_1",
  15. "value": "25"
  16. }
  17. ]


w jaki sposob prawidlowo wyslac to do PHP uzywajac ajax?

  1. $.ajax({
  2. url: "t.php",
  3. type: "GET",
  4. data: { tablica: zmiany },
  5. success : function(data) {
  6. //var dane = $.parseJSON(data);
  7. console.log("ok");
  8.  
  9. var dane = $.parseJSON(data);
  10. console.log(dane);
  11.  
  12.  
  13. },
  14. error : function() {
  15.  
  16. }
  17. })


wyswietla sie blad

jak bezposrednio w PHP tablice przypisze do zmiennej $q a nastepnie daje

$q = (json_decode($q));

foreach ($q as $row){
echo $row->id;
}


to wyswietla kolejno idki z tablicy wiec zakladam, ze zle wysylam tablice do phpa

na froncie tworze tablice
  1. zmiany = [];

a potem dodaje do niej

  1. zmiany.push({
  2. id: apartament,
  3. name: name,
  4. value: value
  5. });



z gory dziekuje za pomoc

Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
blokern
post
Post #2





Grupa: Zarejestrowani
Postów: 107
Pomógł: 0
Dołączył: 27.02.2008

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


dodałem jeszcze print_r($q);
  1. Array ( [0] => Array ( [id] => 3 [name] => in_1 [value] => 123 ) [1] => Array ( [id] => 10 [name] => in_1 [value] => 123 ) [2] => Array ( [id] => 15 [name] => in_1 [value] => 123 ) )
  2. Warning: json_decode() expects parameter 1 to be string, array given in D:\laragon\www\crm\t.php on line 32
  3.  
  4. Warning: Invalid argument supplied for foreach() in D:\laragon\www\crm\t.php on line 34
  5. {"komunikat":"OK OK OK OK OK OK OK "}


Ten post edytował blokern 26.01.2022, 18:24:13
Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 29.12.2025 - 04:54