Solved

jquery ajax web services

Posted on 2015-01-26
3
219 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Suggested Solutions

How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

856 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