weixin_33693070 2014-05-14 14:44 采纳率: 0%
浏览 49

金字塔json查看ajax调用

I have never really worked with ajax before, so would you please be elaborate in your answers..

I have a Pyramid application where I want to load information via ajax because pre-loading it would not be feasible. So I want to load the information I need through a pyramid view, but I am unsure how to do this.
The information I need to fetch is in a MySQL database, so I guess I need to import the mouse click event object ajax_id into views.py in order to do the query. (I can get ajax_id without a problem)

In my views.py I have:

@view_config(route_name="info_ajax",renderer="json")
def info_ajax(self):

    #for the sake of this example, lets just return the information from the mouse click event
    A = ajax_id      #is the id of the mouse click event
    B = ajax_name    #is the name of the mouse click event

    return {
                'a' : A,
                'b' : B,
        }

What I would usually do is to preload all information, but that would take to long in this case, so I cannot just make a list of MySQL queries in views.py and then do <script>window.coords = ${a|query_list};</script> in my .mak file.

I want to import a and b in my JavaScript code as variables, so that I can use them again without having to reload them if need be. How do I go about doing this?

  • 写回答

2条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度