S
S
smoky-jo2019-10-12 22:42:57
PHP
smoky-jo, 2019-10-12 22:42:57

The simplest example of outputting strings from a database to an input in a smarty template via Ajax?

hello, please tell me the simplest sketch of a working example. I have a table that contains all the cities, I want to make it so that when you start entering the first letters in the input, matches are displayed, something like in select2 you wrap the usual select. The smart template is used.

In one file there are queries to the database, such

function userRegion($id) {

    global $db;
    $user_region=$db->fetchRow("select `gorod` from ".TABLE_USERS." where `id`='$id'");
    if(!$user_region) return 0;
    return $user_region;

  }


from it are transferred to another file like this and then output in the template

$user_info_get = $usr->getInfoForUser($crt_usr);
$smarty->assign("user_info_get", $user_info_get);


in html,

{if $user_info_get}{$user_info_get}{/if}

how can I receive requests in Ajax and display them in input with the same solution, tell me a complete example, because I don’t know Ajax at all, many say it’s easy, but I have no idea how, for the sake of one script I don’t want to learn everything to sit, but I haven't found any examples.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question