Can't get return value from VB.NET method in Jquery using $.ajax

Posted on 2010-03-24
Medium Priority
Last Modified: 2012-05-09
I'm a noob at jquery and ajax.  Bascially I have a vb.net class file that is calling some webservices.  I need to return the parsed values of the webservice calls back to the original page.  When I try it according to posted examples the return value is always null.  As a test I changed the vb.net file to return a hardcoded value and still nothing.  Does my vb file have to be a webservice?  I've seen several examples that are.  Below is my code:
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Xml
Imports System.Xml.XPath 
imports System.Web.Services

Partial Class getInfo
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    End Sub

    public function getInfo(ByVal Postal As String) as string
	return "hi"
    end function

    protected sub dosomethingelse()
    end sub
End Class

<script type="text/javascript" src="/js/jquery-1.4.2.min.js"></script>

<script language="javascript">
$j = jQuery.noConflict();

function Postal()
	if (document.getElementById('txtPostal').value == '')
		alert('Please enter a valid postal code');
		$j.post("http://devsite/GetInfo.aspx", {postal: document.getElementById('txtPostal').value}, function(data){alert(data);});

Open in new window

Question by:afacts
LVL 19

Accepted Solution

Albert Van Halen earned 2000 total points
ID: 28483100
You have to output something.
Since it's a page, the content of the page is the response of your ajax call.

You can also create a handler which doesn't have the 'overhead' of the page cycle (init, load, prerender, etc.) which is way faster.
Have a look here : http://www.aspnettutorials.com/tutorials/advanced/httphandler-aspnet2-vb.aspx

Author Closing Comment

ID: 31706764
That was it ... I just needed to do a response.write of the values that I wanted returned.  Thanks!  I don't have much page overhead because the aspx is blank ...

Featured Post

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
An ASP.NET Web Form User Control is not newly introduced in ASP.NET. In fact, it was an old technology yet still playing a role to generate web content, especially when we want to use it to have a better and easy way to control part of the web conte…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month5 days, 10 hours left to enroll

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question