2 Replies - 1826 Views - Last Post: 22 March 2013 - 11:17 AM

#1 Keylogger   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 353
  • Joined: 14-February 11

Fill array jquery with PHP

Posted 22 March 2013 - 07:04 AM

combotest.php:
$response[] = array('ok' => true, 'name' => 'yellow', 'ok' => false, 'name' => 'red');
echo json_encode($response);

index.php
$(function() {
	var arr = new Array();
	$.get("combotest.php", function(i, data){
	     arr = data;
             alert(data.msg);
	}, "json");
});

But it continues to give me = "undifined".

Is This A Good Question/Topic? 0
  • +

Replies To: Fill array jquery with PHP

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: Fill array jquery with PHP

Posted 22 March 2013 - 08:38 AM

well, firstly it would alert undefined (not undifined).

second, your data is a string, not an array (you would need jQuery’s $.getJSON() or at least the json data type)

and finally, there is not even a "msg" key in the array.
Was This Post Helpful? 0
  • +
  • -

#3 Keylogger   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 353
  • Joined: 14-February 11

Re: Fill array jquery with PHP

Posted 22 March 2013 - 11:17 AM

You're totally right. Just solved it a few hours ago. Thank you!

This post has been edited by Keylogger: 22 March 2013 - 11:17 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1