Jump to content
Sign in to follow this  
jonsmau

WebApplication com Webservice

Recommended Posts

jonsmau

Estou a desenvolver uma aplicação Web no netbeans e preciso de usar um WebService criado em asp.net. Para aceder ao WebService estou a usar uma função jQuery no HTML.

O exemplo da função jQuery e o código HTML que uso é o seguinte:

<html>
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript" src="jquery-1.3.2.js"></script>

<script type="text/javascript">
	function serviceCall() {
		$.ajax({
			type: "POST",
			url: 'http://localhost:6335/Service1.asmx?op=TestMethod'
			data: null,
			contentType: "application/json; charset=utf-8",
			dataType: "json",

			success: function (msg) {
				alert("entrou!");
				$("#divResult").html(msg.d);

			},
			error: function (e) {
				alert("não deu");
				$("#divResult").html("WebSerivce unreachable");
			}
		});
	}

</script>
</head>
<body>
<form id="form1" runat="server">
<div style="width: 100px; height: 30px; background-color: yellow;" onclick="serviceCall();">
	Click me</div>

<div id="divResult" style="margin-top: 20px;" runat="server">
</div>
</form>
</body>
</html>

E o código do WebService:

namespace WebService1
{
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[system.ComponentModel.ToolboxItem(false)]
 [system.Web.Script.Services.ScriptService]
public class Service1 : System.Web.Services.WebService

}

Ao executar a aplicação Web o erro que me aparece é o seguinte:

Origin http://localhost:8084 is not allowed by Access-Control-Allow-Origin.

Alguém conhece uma solução que me possa ajudar?

Edited by jonsmau

Share this post


Link to post
Share on other sites
ErasedGOD

tens isso bem configurado? url: 'http://localhost:6335/Service1.asmx?op=TestMethod' vs http://localhost:8084 ?

Share this post


Link to post
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
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.