Solved

jquery ajax web services

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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

21 Experts available now in Live!

Get 1:1 Help Now