-1

I want to write a javascript-based front, which can get data from an external url and display them in the page. Is there any sample code? Thank you.

The server side has a python script, which can generate some data result. I need to get the data and display them. I may need jQuery to make a query to the server, but I don't know how to do it.

I would like to have a button, after I click the botton, it can generate the query which can get the data from the server and display it in the page.

To be brief, The front is javascript and the back is python. I need to make a query from the front to the back and run the python, then I can get some data. Then I need to display the data on the page.

4
  • possible duplicate of How to get data with JavaScript from another server? Commented Jun 21, 2012 at 0:42
  • 2
    Way, way too broad. Is there any specific part of this task you need help with? Commented Jun 21, 2012 at 0:42
  • window.location="http://stackoverflow.com"; Commented Jun 21, 2012 at 0:44
  • What research have you done? What have you already tried? Take a look at stackoverflow.com/questions/how-to-ask Commented Jun 21, 2012 at 1:18

1 Answer 1

1

You might Google XMLHttpRequest. Wikipedia has a pretty good looking entry describing general technique, caveats, and restrictions.

Adapting from Wikipedia, you might start with this (assuming you're not using some ancient version of Internet Exploder):

<html>
<head></head>
<body>
    <script language="JavaScript">
        xmlhttp=new XMLHttpRequest();
        xmlhttp.onreadystatechange = function() {
                if(xmlhttp.readyState == 4){
                    alert(xmlhttp.responseText);                
                }
        };
        xmlhttp.open("GET","somepage.xml",true);
        xmlhttp.send(null);
    </script>
</body>
</html>

Alternately, common libraries such as jQuery can be used to simplify code making remote requests.

Sign up to request clarification or add additional context in comments.

4 Comments

Hi Managu, the page is not a xml page, it is just a html. And the server is running python. I just need to make a query to the url and get the data back and display them. I know i need to use jQuery, but I just don't know how to use it...
@user1470750: The naming of XMLHttpRequest is unfortunate, a legacy of its birth. In practice, XMLHttpRequest is used to fetch text, JSON, XML, HTML, or just about any other data format you can imagine.
Is the data you're fetching from the server going to be a complete document, just a fragment of HTML, or something else entirely? Do you want the result to replace your current page, or do you just want to add something to your page? If you want to fetch something and add it to your current page, you're likely going to be working with XMLHttpRequest. Or using a library which wraps XMLHttpRequest.
If you're certain you need jQuery, perhaps you should modify your question to be "How do I do (this) with jQuery?"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.