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

I have created webservice in new project
public string GetProductsJson(string prefix)which is returning Json data
and I am calling that webservice by using jquery like this from another project

JavaScript
$.ajax({

    type: "POST",
    url:"http://localhost:3904/Service1.asmx/GetProductsJson",
    data: "{'prefix':'" + $(this).val() + "'}",
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    crossDomain:true,
    success: function(response) {
//getting data by using (response.d)
},
error: function(request, status, error) {
                        alert(request.responseText);
                    }
});


I have used different-different url

http://localhost:3904/Service1.asmx/GetProductsJson
http://localhost:3904/Service1.asmx?GetProductsJson
http://localhost:3904/Service1.asmx?op=GetProductsJson

but I am not getting any response.


If I put Service & Client code in single project then it works fine.

Please help me..

-Dattatrya Moin
Posted
Updated 23-Feb-12 21:53pm
v2
Comments
Michel [mjbohn] 24-Feb-12 3:54am    
code tags added
Martin Arapovic 24-Feb-12 4:32am    
Hi! What error it gives you back?! Install firebug and check error in console. It seams that you have some errors related to CORS (http://en.wikipedia.org/wiki/Cross-origin_resource_sharing) and different domains...
[EDIT]
One more thing. Set your dataType to jsonp and make sure that you are using GET method and in your service method make sure that you return data in jsonp format. Example: callbackFunction({"Your pson reponse here"});

Use google if you need more info about stuff that i wrote in comment... :) Good luck..

If you call the webservice from another project is that webservice running via Visual Studio or via IIS? When it runs via visual studio the service that runs it will assign a unique port (3904 in this case), but through IIS you need to remove the port (thus: http://localhost/Service1.asmx?...)

A quick test: open the webservice project in VS and launch it (below in the status bar on the right in window you should get a message that it is running) Leave the project runnning and open your other project containing the JQuery project. Run it.

Hope this helps.
 
Share this answer
 
I got the solution

please visit this site. It is very helpful while calling cross-domain web services
using ajax.

http://www.simple-talk.com/dotnet/asp.net/calling-cross-domain-web-services-in-ajax/


- Dattatrya Moin
 
Share this answer
 
Comments
Santhosh23 7-Jan-13 10:12am    
Hi Frnd,
How to given correct url.. in your ajax method. me also tried in different ways. please send me your code.. or give me your suggestion
thank u

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