Home / ASP.NET Wiki / Javascript / AJAX / Ajax With Javascript

Ajax With Javascript

 Rate It (1)

Create a simple page like

Default.aspx


<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <title>Untitled Page</title>

    <script language="Javascript">
function xmlhttpPost(strURL) {
   // alert(strURL)
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {alert('hi');
            updatepage(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(getquerystring());
}

function getquerystring() {
    //var form     = document.forms['f1'];
//    var word = form.word.value;
//    qstr = 'w=' + escape(word);  // NOTE: no '?' before querystring
//    return qstr;
}

function updatepage(str){
    alert(str)
    document.getElementById("result").innerHTML = str;
}
    </script>

</head>
<body>
   <form name="f1">
  <p>word: <input name="word" type="text"> 
  <input value="Go" type="button"
        onclick='JavaScript:xmlhttpPost("http://localhost:2835/website1/WebService.asmx/HelloWorld")'></p>
  <div id="result"></div>
    </form>
</body>
</html>

Then Create a webservice

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
     Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function

End Class

 

http://dotnetclassic.com/post/AjaxWithJavascript.aspx 

Revision number 1, Tuesday, April 01, 2008 8:38:46 AM by m imran shafiq

Comments

What do you mean by : "Ajax With Javascript" ?? Do you really know what AJAX mean?

AJAX cant be without javascript (Asynchronous Javascript and XML) Btw nice article... I guess what you are trying to exhibit is also popular as javascript services

Good!

Nice!!!

can somebody explian me why we are using- WebService(Namespace:="http://tempuri.org/")> _ WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _

Related Articles

AJAX and CSS

Cascading Style Sheets (CSS) is one of the core technologies in the AJAX architecture apart from XML, DOM, JSON and so forth. Here are some links on using CSS with AJAX: Create flickr-like editing fields using AJAX and CSS/ 26 best ways to implement ajax css

Javascript

JavaScript holds it all together on the client side. There are a number of extensions that have been made to improve and expand base JavaScript object functionality. Blog Posts Four ASP.NET AJAX JavaScript UI Methods You Should Learn: Dave Ward describes more

AJAX

Asynchronous JavaScript and XML - It's Ajax and it's everywhere. Start at the ASP.NET Ajax site and work from there...there's a ton of resources at your disposal. Ajax Showcase - Check out some of the great sites that been built using Ajax. Ajax

Jquery Cross-Domain ajax call using JSONP

Hi everyone. We all know the role of ajax and its implementation. We can use ajax in asp.net as well as in javascript/jquery. But there is a limitation of same origin policy. i.e. we can only use ajax to post and get requests within our site. We can call webservices

Shortcuts

Table of Contents

Top Wiki Contributors

(last 30 days)

  1. abiruban (1)