Click here to Skip to main content
13,798,638 members
Rate this:
Please Sign up or sign in to vote.
i created a asmx web service and running on localhost:5739 and created a html page out side of the port and trying to call web service from jquery. i am always it is going in to onError function and displaying undefind;

asmx web sercie is
// <summary>
/// Summary description for testservice
/// </summary>
[WebService(Namespace = "")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
public class testservice : System.Web.Services.WebService {

    public testservice () {

        //Uncomment the following line if using designed components 

    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public string HelloWorld(string text) {
        return "Hello World" + text;

asmx web service web. config is

<?xml version="1.0"?>
  For more information on how to configure your ASP.NET application, please visit
    <compilation debug="true" targetFramework="4.0"/>

Jquery web service call mwthod is

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
    <script type="text/javascript" src="../JS/jquery-1.8.1.js"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $('#btn_test').click(function () {
                var name = "Kartheek";
                    type: "POST",
                    url: "http://localhost:5739/asmxservices/testservice.asmx/HelloWorld",
                    data: '{ "text": "Kartheek"}',                    
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    success: OnSuccess,
                    error: OnError


                function OnSuccess(data, status) {

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


        <input id="btn_test" type="submit" value="testservice" /></p>

In Inspect element headers are


Request URL:http://localhost:5739/asmxservices/testservice.asmx/HelloWorld
Request Method:OPTIONS
Status Code:500 Internal Server Error
Request Headersview source
Access-Control-Request-Headers:origin, content-type, accept
User-Agent:Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.89 Safari/537.1
Response Headersview source
Content-Type:text/html; charset=utf-8
Date:Thu, 13 Sep 2012 10:24:52 GMT
Server:ASP.NET Development Server/
Posted 13-Sep-12 1:30am
Updated 13-Sep-12 3:28am
Kuthuparakkal 13-Sep-12 6:34am
what's that "error" error ?
Kartheek.chakrala 13-Sep-12 6:36am
always it is going in to onError
Sushil Mate 13-Sep-12 7:14am
what was the error message?
Kartheek.chakrala 13-Sep-12 7:19am
always it is going in to onError
CodeHawkz 13-Sep-12 7:35am
@Kartheek: They are asking what is the 'msg' you get on 'OnError()' method :)
Kartheek.chakrala 13-Sep-12 7:40am
Undefined only i am getting nothing any message
ZurdoDev 13-Sep-12 8:32am
msg.d IS undefined in the OnError event. From the error signature is error(jqXHR, textStatus, errorThrown). Examine those values and you'll see the error. Look at jqXHR.responseText.
Kartheek.chakrala 13-Sep-12 8:57am
i found the problem but not the solution
Problem is Cross Domain Webservice Call

solution till now dnt know. If any body have simple solution ?
darshan_ur 13-Sep-12 10:09am
IF the problem is with cross domain, then you could try adding a crossdomain.xml file in your asmx folder to allow cross domain access.
Examples of crossdomain.xml are given in below link:
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Solution may be in the following links

1. The same type of problem is discussed Here[^].
Here he talks about JSNOP.
The last post[^] in that Question is the solution what he talks about.
Please take a look, it may help.

2. So many accepted solutions in JqueryAjax Webservice and Crossdomain problem[^].

3. Awesome article illustrating the concept - Calling Cross Domain Web Services in AJAX[^].

4. Another example - Jquery Cross-Domain ajax call using JSONP[^].

5. Nice discussion with solutions in cross domain access to service from javascript[^].

All the best.
Kartheek.chakrala 20-Mar-13 5:12am
JSONP is for Get Request we can't post data with it
derloopkat 28-Sep-13 12:00pm
It doesn't work.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

This article may help you but it's written in, use online conversion tool if you want to convert it in c#, good luck.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01 | 2.8.181207.3 | Last Updated 6 Dec 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100