誰かがJQueryを使用してJavascriptからPythonスクリプトを呼び出し、Pythondictである結果を解析する方法の短いコード例を教えてもらえますか?今まで持っていたものを下回っていますが、動作しません。
Pythonコード(script.py):
def pythonFuntion():
dict = {"val1":"this is x", "val2":True}
return json.dumps(dict)
中級PHP(intermediate.php):
<?php
exec("python script.py", $output);
echo $output;
?>
Javascript:
<script type="text/javascript" src="jquery-1.8.3.js"></script>
<script type="text/javascript">
$.ajax({
url: 'intermediate.php',
type: 'POST',
dataType: "json",
success: function(data){
alert(obj.val1);
}
});
</script>