简体   繁体   English

处理对WCF REST服务的jQuery AJAX调用的数据部分

[英]Handling the data portion of a jQuery AJAX call to WCF REST service

Fairly new to jQuery, I have a .ajax call going to a WCF RESTful service and my Uri template on the operation contract is the following: 对于jQuery来说,这是很新的东西,我有一个.ajax调用,它会转到WCF RESTful服务,并且我在操作合同上的Uri模板如下:

UriTemplate = "/{appName}/{custCode}/{custUserName}/counter"

My problem is, I have a what is either going to be XML or JSON that I want to save to a database via the service and I'm confused how to get the service to receive the payload without having it as a variable in the Url. 我的问题是,我有一个要通过服务保存到数据库的XML或JSON,而我困惑如何使服务接收有效载荷而不将其作为Url中的变量。

My AJAX call looks like this so far: 到目前为止,我的AJAX调用看起来像这样:

$.ajax({
   type: "POST",
   url: ‘{../{appName}/{custCode}/{custUserName}/counter}’
});

Any help would be appreciated. 任何帮助,将不胜感激。

If I'm reading your question correctly, I think that you're asking how to send data to that server via ajax. 如果我正确阅读了您的问题,则认为您正在询问如何通过ajax将数据发送到该服务器。

What you need to do is specify what the data is and add it to the 'data' setting in your ajax request. 您需要做的是指定数据是什么,并将其添加到ajax请求中的“数据”设置中。

So 所以

var myData = "whatever your data is";
$.ajax({
    type="POST",
    url: ‘{../{appName}/{custCode}/{custUserName}/counter}’,
    data: myData
 })

You can also specify what to do with the response you get, perhaps letting the user know his/her data was saved or some such. 您还可以指定如何处理收到的响应,也许让用户知道他/她的数据已保存或类似的内容。 http://api.jquery.com/jQuery.ajax/ is the list of all settings. http://api.jquery.com/jQuery.ajax/是所有设置的列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM