开发者

Requests with Jquery in PHP

开发者 https://www.devze.com 2022-12-09 19:16 出处:网络
Currently I\'m trying to add on to the auto-complete module for jquery that is out there.After i\'ve auto-completed my text field, i tab to my next field (a drop down). When that drop down is focused,

Currently I'm trying to add on to the auto-complete module for jquery that is out there. After i've auto-completed my text field, i tab to my next field (a drop down). When that drop down is focused, i 开发者_运维技巧want to check against my text field and populate the drop down with a specific list depending on what the text field has.

Is this something jquery can do? I know I can do this by appending a script tag, and passing values back with json, but wanted to know if I could do something similar to this with jquery.

Thanks in advance.. still discovering this wonderful framework!


This should be no big deal - you read the contents of the text field using $.val() then do $.get(url) to your PHP code that builds an object/array that maybe includes a success/failure flag, and converts it to json (json_encode) and simply echos that back.

something like:

val entry = $('#textfield').val();
$.get('http://yourserver/getvalues.php', { entry: entry }, function(result) {
   if (result.success) {
      var options = result.options;
      $('#select').empty();
      $.each(options, function(key, value) {
         $('<option>').val(key).text(value).appendTo('#select');
      }
   }
}, 'json');
0

精彩评论

暂无评论...
验证码 换一张
取 消