2012-06-01 2 views
0

json 데이터를 클래스 변수 산업 또는 제품에 저장하도록 jQuery $ .get을 얻는 방법은 무엇입니까?

$ .get 호출에서 PHP 파일로 반환 된 데이터를 보면 jSon 배열을 반환하지만 정보를 사용할 수는 있지만 리턴 된 내용을 저장하는 것이 더 중요합니다. Profile 클래스의 글로벌 변수

Profile=new Profile("kazie.php"); 
Profile.getProfile(0123, 'Kayla', '[email protected]'); 

var Profile = function(php_file){ 
    this.php_file=php_file; 
    this.serial; 
    this.industry; 
    this.product; 
    //Also need to access scope as well 
}; 

Profile.prototype={ 

    getProfile:function(serial, name, email){ 

     $.get(this.php_file,{action: "retrieve_profile", serial: serial, name: name, email: email}, 
      function (data){ //Return a json array of our new profile 
        //Data is an array of properties. array("industry"=>"Retail"); 
        //I need to assign these properties to my global variables for 
        //***How to I get data["industry"] to store in Profile.industry?** 


       }, "json" 
      ); 

    } 
} 

답변

0

당신에게 반환 된 JSON (이 기능으로 전환 할 필요가 없습니다주의를 처리하는 방법에 대한 몇 가지 아이디어를 줄 것이다 .getJSON 기능에 대한 문서, 그들은 당신이 지정한 주어진 동등한 것 "JSON ", .getJSON은 편리한 메소드이다). 그것은 내가 할 수있는 것보다 더 잘 설명한다.

0

이 시도 :

... 
function (data){ 
      Profile.prototype.industry = data.industry 
    }, "json" 
); 
... 

이 클래스의 프로토 타입으로 업계를 저장해야합니다. 프로토 타입에 저장하지 않으려면 (모든 인스턴스에서 사용 가능하게 만들 수 있음) 필요로하는 인스턴스 만 저장해야합니다.

관련 문제