Click here to Skip to main content
15,921,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am trying to call a web method of a web service from a simple javascript file. This javascript file could be added to any other project and it needs to talk to database and fetch some data.
I do not want to add a webservice.htc file or have a web reference as this will totally nullify the above goal.
All I would like to know is, is there a better and straight forward way to call a ASP.Net 3.5 web service from a javascript?
If so, please let me know

Thanks,
Raam
[Email removed to avoid spam]
Posted
Updated 6-Oct-10 9:13am
v2

you can call web service by ajax.
Example:
JavaScript
var J = jQuery.noConflict();

function PreLoadMouseOverImages() {
    var i = 0;
    J.ajax({
        type: "GET",
        url: "webservice1.ashx",
        success: function (msg) {

            //msg is the response data
            // you can do your work here.
        }
    });
}
 
Share this answer
 
v2
hi,

googling for "javascript xmlhttp".
it might help you.
 
Share this answer
 
XMLHttpRequest() works within my domain. If I try to access a different domain URL, the request isn't going?
Please let me know

Thanks,
Raam
 
Share this answer
 
Comments
Dylan Morley 7-Oct-10 11:14am    
That's to prevent cross domain scripting and is part of the same origin policy of javascript

https://developer.mozilla.org/En/Same_origin_policy_for_JavaScript

You can proxy your javascript call to a web service within your domain, then have that web service call the required resource on the other domain
Hi,

Could anyone please let me know how to call a different domain from my native domain's javascript?
The issue is:
1. I have a javascript file hosted on say domain called 'a'
2. I have a aspx file hosted on domain 'b'
3. I need to call domain b's aspx from my domain a's javascript

I tried all the possible ways including cross domain cookie and XMLHttpRequest

Since the approach should be a light weight, we do not want to have a script manager and point the path reference to domain b

Please let me know ASAP

Thanks,
Raam
 
Share this answer
 
Look here

http://snook.ca/archives/javascript/cross_domain_aj[^]

Cross domain proxy is one I've used a number of times.

So, design a method on your web server that calls the remote domain resource.

Your javascript calls your web method, which in turn calls the remote resource. You are proxying the data through your web server and you can call your method from script because it's within the same domain.
 
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