Jump to content
Sign in to follow this  
nusun

Ajax request PHP

Recommended Posts

Sveiki.
Datus saņemu, visu redz.
Bet teiksim ja pieprasu alert(data[11]); Man izvada 12 simbolu. Es saņemu visu kā stringu.
Šķiet, ka strings ir dēļ echo, bet ar return es neko nesaņemu.

 

// On click load event	
$('img#thisnut').one("click",function(){
			$.ajax({
			url: "load.php",
			type: "POST",
			async: false,
			success: function(data){
				alert(data[0]);
				alert(data[1]);
			},
			error: function(){
				alert('Error');
			}
			});
	});
//php side
	$rez = array();
	$sql = mysqli_query($conn, "SELECT score, prop FROM deeznuts WHERE member_login_key='".$pin."'");
	while($row = mysqli_fetch_array($sql)){
		$rez[] = $row;
	}
	echo json_encode($rez);
	}

 

Share this post


Link to post
Share on other sites

Īsti nesapratu, ko Tu gribi, bet uzreiz varu pateikt, ka ajaxā norādi dataType un contentType. Cik sapratu, tad veic pieprasījumu pēc ieraksta no datubāzes un ja tā ir, tad kāpēc tips ir POST? Drusciņ detalizētāk lūdzu..

Edited by Kwaithex

Share this post


Link to post
Share on other sites

success: function(data){
  data = JSON.parse(data);
  console.log(data);
}

  • Upvote 3

Share this post


Link to post
Share on other sites
12 hours ago, LoyC said:

success: function(data){
  data = JSON.parse(data);
  console.log(data);
}

Paldies. Tas bija tieši tas ko vajadzēja. Visu izdevās sataisīt. :)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.