Skip to content
Advertisement

ASP.NET VB WebService request with AJAX 500 error

I’m trying to run an AJAX Webservice request on a VB ASP.NET page.

When the page loads, I’m trying to call the webservice but I get a 500 error in the console.

My WebService file looks like this:

JavaScript

My ASP.NET page looks like this:

JavaScript

I expect the page to load and a message box to popup server side that says ‘hello_world’ as well as the web browser to create a popup that says the same. However, this does not happen as I get a 500 error instead.

I’ve tried to fix this by using different versions of jQuery as well as enabling requests in the web.config file like this:

JavaScript

This doesn’t work and I still get that “the server responded with a status of 500” in the web browser console. No errors are logged within the application’s debug console.

How can I fix this?

Advertisement

Answer

Ok, assuming both pages are in the SAME folder – at the same level?

Then this should work:

JavaScript

Note how your data has to match your parmaters..

So, say you have this:

JavaScript

And note how we set the function as string – you should give the function a type – in this case “string”.

JavaScript

Edit:

Follow up question was how to return more then one value?

Well, the easy way? Create a structure or class – let the built in serialization convert that to a json string for you.

So our web method could say be this:

JavaScript

I often use a struct in place of a class – since then I just shove it in right before my web method as per above.

Now, lets drop in a button on the page – and js function to call this:

eg:

JavaScript

And when we run, we get/see this:

enter image description here

So, you can often just return a simple string. But, if you create a structure server side, then you can quite much reference the result client side as a js object as per above.

Advertisement