jquery - python code from javascript using ajax -


i have seen topic: ajax request python script trying need there 1 information missing.

$.post('mypythonfile.py',{data}, function(result){ //todo } );

now problem is: how call function inside mypythonfile.py? there way specify name of function , give input data? thank time.

ajax calls making http requests,so need have http server handles requests seen in other question. (there cgi provide http request handling). in python can use django, bottle, cgi etc have http request handling. call python function javascript.

edited :

in url.py should define api url;

(r'^myapi', 'myapi'), 

and on url should have web api in views.py. can ;

def myapi(request):     callyourfunction(); 

and can call javascript now. can use jquery ajax request;

 $.ajax({             type:"get",             url:"/myapi",             contenttype:"application/json; charset=utf-8",             success:function (data) {                  },             failure:function (errmsg) {             }         }); 

the http method type not matter, if wanna run python script. if wanna send data javascript python can send data json python post method.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -