Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to call a web service from a local file ( HTML5 + Javascript/JQuery).

due to "Same origin policy" i am unable to send request.

i want to enable for only this page .
Posted
Comments
ParthaDinda 18-Sep-12 5:46am    
can you post some code what ever you tried?
Kartheek.chakrala 18-Sep-12 6:19am    
from html
$('#btn_test').click(function () {
$.ajax(
{
type: "POST",
url: "http://localhost:5739/asmxservicestestservice.asmx/HelloWorld",
data: '{ "text": "Kartheek"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
error: OnError

});

function OnSuccess(data, status) {
alert(data.d);

};
function OnError(msg) {
alert('error = ' + msg.d);
}

});


and my web service which is running on http://localhost:5739


[WebMethod ]
[ScriptMethod( ResponseFormat = ResponseFormat.Json)]
public string HelloWorld(string text)
{
return "Hello World" + text;
}
ZurdoDev 18-Sep-12 7:53am    
It's a browser setting, right? You'll have to change your browser or use a console app you write or something.

1 solution

One solution to your problem would be to use JSONP instead of JSON.

Here is an excellent CP article on it,

JSON to JSONP: Bypass Same-Origin Policy[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900