Solved

jquery ajax web services

Posted on 2015-01-26
3
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
 
LVL 1

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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

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.
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
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 …

691 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