English 中文(简体)
穿透沙丘和 Java之间变数
原标题:Passing variables between Python and Javascript

相信你需要撰写一些 Java文,在改变下级名单时简单地改变一套检查箱。

根据清单中选取的项目,一些检查箱将受到检查/检查。

反之,你与一些Kalkaschemy一道制定了沙尔法。

Java稿需要按照惯例确定清单中选定的项目,将其退回到“灰色”模块,然后将一些Alchemy中的变量用于退回一个需要核对的检查箱清单,即: “User selected Ford , soeck Boxes Focus , Mondeo , Fiesta need to beecked”

问题在于,我似乎必须找到一条途径,从Javascript处进入on语模块,而不要将iv块变成一个小型浏览器页,然后将含有变数的斜体插入一页!

Does anyone have any ideas on how this should work?

最佳回答

Funny, I ve got web pages withalle Java that discuss to ZhuGI elements that useAlchemy.

我这样做的是,我提出非洲驻军的请求,但要求安理会不要采取XML。

贾瓦斯·本古兰认为:

function on_request_success(response) {
    console.debug( response , response);
} 

function on_request_error(r, text_status, error_thrown) {
    console.debug( error , text_status + ", " + error_thrown + ":
" + r.responseText);
}

var request = { ... };
jQuery.ajax({
    url:  http://host/whatever.cgi ,
    type:  POST ,
    cache: false,
    data: JSON.stringify(request),
    contentType:  application/json ,
    processData: false,
    success: on_request_success,
    error: on_request_error
});

就像这一点一样:

request = json.load(sys.stdin)
response = handle_request(request)
print("Content-Type: application/json", end="

")
json.dump(response, sys.stdout, indent=2)

值得注意的是,它使用“灰尘”模块,因为整个申请都是作为“智者”在身体上提出的。

问题回答

python有一个json模块,该模块最适合这一设想。

利用一个老的美国宇宙航空研究开发机构,用json作为数据格式,将允许你在javascript和贵的on模块之间交换数据。

(除非你的餐厅模块在客户方面运行,但我看不出你如何从浏览器中执行)。

Ajax is a good way to pass variables between python and javascript. Javascript:

 param = {a: hello , b:  world , c:  ! }
   

        $.ajax({
            type: "post",
            url: "scpi.py",
            cache: false,
            async:  asynchronous ,
            dataType:  html ,
            data: param,
            success: function(data) {
                console.log(data)
               
            },
            error: function(request, status, error){
                console.log("Error: " + error)
            }
        })

Server.py: (You will need a three functions for this to work)

    def do_POST(self):
    if "scpi.py" in self.path:
        form = cgi.FieldStorage(
            fp=self.rfile,
            headers=self.headers,
            environ={ REQUEST_METHOD :  POST }
        )
        a = form[ a ].value
        b = form[ b ].value
        c = form[ c ].value

        content = myfunction(a, b, c)
        self.respond(content)      

def handle_http(self, data):
    self.send_response(200)
    self.send_header( Content-type ,  application/json )
    self.end_headers()
    print(data)
    return bytes(str(data),  UTF-8 )
    
def respond(self, data):
    response = self.handle_http(data)
    print(data)

FYI:“故障(a、b、c、)”是另一个假日文件的功能,然后将数据归还给自己。 回复





相关问题
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 ]="...

热门标签