1

This is my JQuery code -

                $("#test_link").click(function() {
                jQuery.ajax({
                    type: "POST",
                    url: "http://localhost:8882/Hello.aspx",
                    data: '',
                    cache: false,
                    success: function(response)
                    {
                        alert(response);
                    }
                });
            });

Hello.aspx simply prints 'Hello World'. When I click on the link it shows a alert with the following response -

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > 
<html>
<head>
<title>Hello World</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema content="http://schemas.microsoft.com/intellisense/ie5">
</head>
<body MS_POSITIONING="GridLayout">
Hello World
</body>
</html>

Ideally it should just 'print Hello World'

4
  • if it's Json Data type, then alert(respnse.d) Commented Mar 21, 2012 at 6:46
  • What happens when you try to access the Hello.aspx page directly? Does it give the same error? Are you using the same ports? It could be a cross-domain issue (port 80 calling port 8882) Commented Mar 21, 2012 at 6:47
  • @JusticeErolin it works perfectly fine when I access Hello.aspx page directly Commented Mar 21, 2012 at 6:48
  • hi Sachyn u see this forbidden error in all browser. Please try that in IE and tell me if any issue. Commented Mar 21, 2012 at 6:58

3 Answers 3

1

Maybe your client test page an the HelloWorld.aspx are on different ports or use a different URL? Try using a jsonp attribute.

jsonp: true

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

2 Comments

yes, they were on different ports. Now I dont get that error any more, however, the response I expect is just 'Hello World', but I am getting entire HTML code with all the tags.
This is the 'response' from your webpage and is expected to work that way. Try creating an html page and in the page only put 'Hello World'. This would then be your response text. You normally would want to return a JSON object or array of JSON objects. Why not try using ServiceStack.NET to create a simple .NET Web Service? There is a NuGet package for ServiceStack hosted as an MVC web app. If you can deploy an MVC app to your IIS instance this is the way to go. If not, you could still run ServiceStack as a Windows Service or in a Console app.
1

you should remove all contents in your hello.aspx file and let only one string that you want to get in yr response. Remove all html tags or try to use the Response.WriteLine("hello world") in the page_load method (see the associated code behind file)

Comments

0

You are using a POST to post the data to hello.aspx. Maybe that is forbidden?

If you are only loading data you can simply use JQuery get in stead of the full Jquery AJAX call: http://api.jquery.com/jQuery.get/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.