English 中文(简体)
A. 与日本宇宙航空研究开发机构一道将多个领域投入
原标题:Sending multiple fields with AJAX

I m trying to figure out how to send multiple fields with AJAX. Would I use a GET or POST?

页: 1 我希望我的田野能够根据在选定盒子中选择的选项进行更新——我知道我已经知道,为了工作,我很想知道,如何通过XMLHttpRequest,发送多种不同的数据。

i.e.

fname = c.execute("""SELECT fname from employees WHERE user = %s;""", (uname))

lname = c.execute("""SELECT lname from employees WHERE user = %s;""", (uname))

email = c.execute("""SELECT email from employees WHERE user = %s;""", (uname))

deptid = c.execute("""SELECT dept_id from employees WHERE user = %s;""", (uname))

active = c.execute("""SELECT active from employees WHERE user = %s;""", (uname))

sentient = c.execute("""SELECT sentient from employees WHERE user = %s;""", (uname))

我将掌握所有这些数据,并希望将其送回我的另一页。 我将如何这样做,以便更新它。

注,我要从服务器上将这一信息发送到客户网页。 一、即,如果用户从客户网页上的选定箱中选择不同的用户名称(此处不显示,将通过POST或GET发送),所有这些领域都将送回我的主页并展示给用户。

最佳回答

虽然我不熟悉Sharma,但我很幸运的是,有办法将你的数据编为JSON,以返回客户。

{"fname" : "Bob", "lname" : "Johnson", "email" : "[email protected]" ... }

在客户方面,你随后能够把数据引向他人,如你想要任何其他 j印对象:

var fname = response.fname; // etc
问题回答

我假定你有某种办法处理客户的要求等? 您必须就客户与服务器之间的一些协议作出决定。 JSON对此非常方便,因为Java语很容易穿透。

因此,将物体序号定在http://docs.python.org/library/json.html:

import json
print json.dumps( { "fname": fname, "lname": lname } ) # etc.

然后请上页;例如,请上页:

$.getJSON( "url/to/page", function( data ) {
    // do something
}




相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签