开发者

Python function return to jQuery var

I've a python script that returns something. In a html page, I use jQuery to send a GET request to this script (with $.get()). I want the "return" of python script in a jQuery/javasc开发者_StackOverflow中文版ript var. Is it possible with jQuery function? Without use JSON or other.


$.get("url", function (response) { 
  var myVar = response;
  // Do stuff with variable here
});

If the response contains HTML, you can use $(response) to get a jquery object to do operations on, but the response object itself is already a string.


Try setting the dataType parameter to HTML. So in the below example return_value is a text representation of whatever is returned by your python script

$.get('http://wwww.example.com/',function(data){
var return_value = data;
}, 'html');


Documentation is a wonderful thing. http://api.jquery.com/jQuery.get/

Specifically you want the fourth example.


Why would you say "without using JSON"? That's exactly what JSON is for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜