Jump to content

Ajax call


Chikwado

Recommended Posts

Some one help on my Ajax page: when you click "try it yourself demo" an excutable file that has been chained with div will dispaly. And those Ajax code, in the head section I did not see where those text was stored, And it is not in the body section. Where is that text been stored and chained to html page. Some one help.

Link to comment
Share on other sites

Which try-it demo are you referring to? Could you link to it?

 

The content received by AJAX is in the responseText property.

 

In the following example, the response is being displayed as the innerHTML of the element <div id="myDiv">

http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_first

Link to comment
Share on other sites

Yes, exactly the link you specified. Now, how to make another file that I will chain with div. For Example: javascript var and data type. It was made like this:

<html>
<body>
<div id="message"></div><script>var people="Excutable text here"; var person="Another Excutable text here"; document.getElementById("message").innerHTML=people + "<br>" +person;</script></body></html> Then, If you process the above code it will display on the div as: Excutable text here. Another Ecutable text here. Because the text has been stored in the varable. But for ajax is different. Now how to make another file that will be display in the div. Is it just to write text in notepad and save it .responseText? Edited by Chikwado
Link to comment
Share on other sites

Yeh in AJAX you can use asynchronous or synchronous.

 

Asynchronous:

 

 

<input type=button onclick='blah()'>function blah(){ sendAjaxRequest();}function onAjaxResponse(ajax){ document.getElementById("message").innerHTML = ajax.reponseText;}

 

Synchronous:

 

 

<input type=button onclick='blah()'>function blah(){ document.getElementById("message").innerHTML = getSynchronousAJAX().responseText;}

 

It's better to use async than sync.

You can also use jQuery to avoid ajax code.

 

<input type=button id=somebutton>$(document).ready(function(){  $('#somebutton').click(function(){    $.get('someurl.php', function(data,status){      document.getElementById("message").innerHTML = data;    });  });});
Link to comment
Share on other sites

I'm not sure what you are trying to do. Are you trying to return executable JS as the response to an AJAX request so that it can be run on the page?

Link to comment
Share on other sites

This is what I mean: just check the link above, when you click "try it yourself demo" a new page will open up saying "Let Ajax change this tex" with a trigable button below it. Then, If you click it a plain text will dispaly. Saying "Ajax is not a new programming language, Ajax is a technique for creating fast and dynamic webpage" my question is this: where have you stored that plain text, how have you manage to stored and what extention does it has? I have those Ajax code in my notepad but what I am thinking is: how will I store excutable text for it. More help, Thank you.

Link to comment
Share on other sites

"Executable" is not the right word for this. Executable refers to binary files that the operating system interprets as a program.

 

AJAX is a technology that loads content from a file. You tell AJAX where the file is and it will load the content. In the example it is loading the text that is stored in a file called "ajax_info.txt". Here's a link to that file so that you can see it for yourself: http://www.w3schools.com/ajax/ajax_info.txt

 

The extension of the file doesn't matter, AJAX loads whatever is in the file regardless of what extension it has. It could be called "ajax_info.txt", "ajax_info.html" or "ajax_info.js" and it wouldn't make a difference.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...