Ajax调用的Python脚本

I want to call a python script using javascript (AJAX). I think this is working (I don't get any errors).

This is my ajax and html code:

<!DOCTYPE html>

<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script>


<table id="table">
   <tr>
       <td id="col1">
           <form>

               <p><label for="text"> your text</label>:<input type="text" id="text"></input></p>

               <input type="button" value="tester" onclick="addImage()" />
           </form>
       </td>
       <td id = "img"></td>
   </tr>
</table>

<p id="result"></p>



<script>
function callPy(data1, data2){
    $.ajax({
        type: "POST",
        url:"pythonTest.py",
        data:{data1: data1, data2:data2},
        success: callbackFunc
    });
}
function callbackFunc(response) {
    $('#result').html('<li>'+response.x+'</li>');
}
function addImage(){
    callPy(1,2);    
}
</script>

This is the result of callbackFunc: undefined

So I think Python script don't detect data1 and data2 But I don't know how to get data1 and data2 in the python script ...

This is my python script :

import csv
from numpy import genfromtxt
from numpy import matrix

def main(data1, data2):
    x = data1 + data2
    return x
if __name__ == "__main__":
    x=main()
    return x;
查看全部
weixin_33729196
weixin_33729196
2016/08/10 11:54
  • python
  • html
  • ajax
  • javascript
  • jquery
  • 点赞
  • 收藏
  • 回答
    私信

0个回复