javascript - Selectize get PHP array loaded in options using AJAX -


i can't seem find out how results of php query in options selectize. i'm new using ajax, bear me :) when options manually loaded , i'm typing in emailaddress, results visible:

                options: [                 {email: 'test@testcom'}             ], 

now need same result, dynamically. need php array in options field? used json_encode convert json. possible make javascript variable php variable? hope information sufficient, if not plz tell me need add.

this code created selectize:

            $('.emailsearchreceiver').selectize({             persist: false,             maxitems: null,             valuefield: 'email',             searchfield: ['email'],             options: [{email: 'test@testcom'}],             render: {                 item: function(item, escape) {                     return '<div>' +                         (item.email ? '<span class="email">' + escape(item.email) + '</span>' : '') +                         '</div>';                 },                 option: function(item, escape) {                     var caption = item.email;                     return '<div>' +                         (caption ? '<span class="caption">' + escape(caption) + '</span>' : '') +                         '</div>';                 }             },             createfilter: function(input) {                 var match, regex;                  // email@address.com                 regex = new regexp('^' + regex_email + '$', 'i');                 match = input.match(regex);                 if (match) return !this.options.hasownproperty(match[0]);                  // name <email@address.com>                 regex = new regexp('^([^<]*)\<' + regex_email + '\>$', 'i');                 match = input.match(regex);                 if (match) return !this.options.hasownproperty(match[2]);                  return false;             },             create: function(input) {                 if ((new regexp('^' + regex_email + '$', 'i')).test(input)) {                     return {email: input};                 }                 var match = input.match(new regexp('^([^<]*)\<' + regex_email + '\>$', 'i'));                 if (match) {                     return {                         email : match[2],                         name  : $.trim(match[1])                     };                 }                 alert('invalid email address.');                 return false;             }         }); 

this code created retieve emailaddresses:

                    $query = $this->transfer->query( "select distinct emailaddresses.emailaddress                                       transfers                                        join emailaddresses                                        on (emailaddresses.transfer_id = transfers.transfer_id , emailaddresses.type <> 'sender')                                       transfers.created_user_id = $user_id " );                  if(!$query)                 {                     //die connection                 }                 //place emailaddresses in empty array                 foreach ( $query $results => $r )                 {                     $emailaddresses[] = $r['emailaddresses']['emailaddress'];                 }                 json_encode($emailaddresses); 


Comments