from flask import Flask, jsonify
import psutil, time,json
app = Flask(__name__)
@app.route('/test_post/aa', methods=['GET','POST'])
def test_post():
memKeys = ["total", "available", "percent", "used", "free"]
memVaules = psutil.virtual_memory()
memInfo = dict(zip(memKeys, memVaules))
memInfo = {k: str(v / pow(1024.0, 3)) + 'GB' for k,
v in memInfo.items() if k != 'percent'}
memInfo['percent'] = psutil.virtual_memory().percent
return "successCallback"+"("+json.dumps(memInfo)+")"
if __name__ == "__main__":
app.run(
host = '0.0.0.0',
port = 7777,
debug = True
)
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></script>
<script>
$('#search').click(function () {
$.ajax({
type: 'GET',
url: 'http://192.168.1.106:7777/test_post/aa',
dataType: 'jsonp',
jsonpCallback: "successCallback",
success: function (data) {
console.log(data);
}
});
});
</script>