dtoka218420 2015-11-07 13:27
浏览 35

迷茫的框架和javascript ajax组合

I'm traying to make an ajax action in my project which is developed by Userfrosting system (A system that uses slim framework and twig).

There are 2 html select tags in sections.php called country and city. When country is chosen, cities in that country will ve selected from the database and will be shown in city tag with an ajax action.

I can do this with a normal php script, but can't do it in slim.

sections.php

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
  $(document).ready(function() {
    $(".country").change(function() {
      var veri = $(this).val();
      var dataString = 'veri=' + veri;

      $.ajax({
        type: "POST",
        url: "deneme.php",
        data: dataString,
        cache: false,
        success: function(html) {
          $(".city").html(html);
        }
      });

    });
  });

</script>

<label>Country :</label>
<select name="country" class="country">
  <option selected="selected">--Select Country--</option>
  <option value="1">India</option>
  <option value="2">United States</option>
  <option value="3">United Kingdom</option>
</select>
<br/>
<br/>
<label>City :</label>
<select name="city" class="city">
  <option selected="selected">--Select City--</option>

</select>

Posted value 'veri' will be taken by deneme.php and cities in that country will be fetched from database and all the cities will be listed in options.

deneme.php

require_once("../userfrosting/config-userfrosting.php");
require_once "../userfrosting/models/mysql/MySqlSiteSettings.php";

$veri = $app->request->post('veri');
if (isset($veri)) {
  while ($data = $app->site->getCities($veri)) {
    $cities = $data[city];
    echo '<option value="'.$cities.
    '">'.$cities.
    '</option>';
  }

When i choose the country, city option becomes empty and i get this error in error log;

"PHP Fatal error: Call to a member function getAktiviteler() on a non-object in C:\xampp\htdocs\userfrosting\public\deneme.php on line 119"

I used many diffent ways but couldn't solve the problem. Please help !

  • 写回答

1条回答 默认 最新

  • dongyun65343 2015-11-18 07:30
    关注

    As alexw said, i went through UserFrosting and Slim tutorials and restructured my code. There was problem in fetching data from database and also in javascript part. Now my problem is solved. Thanks Alex.

    评论

报告相同问题?

悬赏问题

  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)