Solved

jquery ajax web services

Posted on 2015-01-26
3
207 Views
Last Modified: 2015-01-31
<script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

         function Run() {
             $.ajax({

                 // The 'type' property sets the HTTP method.
                 // A value of 'PUT' or 'DELETE' will trigger a preflight request.
                 type: 'POST',

                 // The URL to make the request to.
                 url: 'http://asdfasdfasdfasdfasd.com/wcf/order/Service1.svc/PostNoData',

                 // The 'contentType' property sets the 'Content-Type' header.
                 // The JQuery default for this property is
                 // 'application/x-www-form-urlencoded; charset=UTF-8', which does not trigger
                 // a preflight. If you set this value to anything other than
                 // application/x-www-form-urlencoded, multipart/form-data, or text/plain,
                 // you will trigger a preflight request.
                 contentType: 'application/x-www-form-urlencoded; charset=UTF-8',

                 xhrFields: {
                     // The 'xhrFields' property sets additional fields on the XMLHttpRequest.
                     // This can be used to set the 'withCredentials' property.
                     // Set the value to 'true' if you'd like to pass cookies to the server.
                     // If this is enabled, your server must respond with the header
                     // 'Access-Control-Allow-Credentials: true'.
                     withCredentials: false
                 },

                 headers: {
                     // Set any custom headers here.
                     // If you set any non-simple headers, your server must include these
                     // headers in the 'Access-Control-Allow-Headers' response header.
                 },

                 success: function () {
                     // Here's where you handle a successful response.
                     alert("Success");
                 },

                 error: function () {
                     // Here's where you handle an error response.
                     // Note that if the error was due to a CORS issue,
                     // this function will still fire, but there won't be any additional
                     // information about the error.
                     alert("Error");
                 }
             });
         }
</script>



    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    string PostNoData();


    public string PostNoData()
    {
        return "No Data";

    }


Now, when I try to run on Firefox and it ends up below error:

Request Method: Post
Status Code: 400 Bad Request

The issue is I can't see the wcf services. And I just want to try out and see what I can do.
0
Comment
Question by:ITsolutionWizard
  • 2
3 Comments
 
LVL 11

Accepted Solution

by:
Dany Balian earned 500 total points
ID: 40571521
try setting the type as GET, and see if the parameters are being sent out correctly, and what the webservice is returning! is the webservice wcf running??
0
 

Author Comment

by:ITsolutionWizard
ID: 40571790
same issue even i try get method
0
 
LVL 11

Expert Comment

by:Dany Balian
ID: 40581191
what error are you getting when you run the code?
and what happens when you type: http://asdfasdfasdfasdfasd.com/wcf/order/Service1.svc/PostNoData in the browser?
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now