Solved

jquery ajax web services

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

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

738 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