English 中文(简体)
Jquery & query string
原标题:Jquery & query string

下面,我把我的上页功能用 j。

Please tell me how to pass query string.

<script type="text/javascript" src="script/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
  $(document).ready(function() {
    $( #Customers ).change(function() {
      $.ajax({
        contentType: "text/html; charset=utf-8",
        data: "CustomerID=" + $( #Customers ).val(),
        url: "FetchCustomer.aspx",
        dataType: "html",
        success: function(data) {
          $("#CustomerDetails").html(data);
        }
      });
    });
  });
</script>

我有几个问题。

  1. when type: "POST", then contentType: "application/json; charset=utf-8", has to be application/json? it can not be html?

  2. when type: "POST" then url can t be like url: "Customer.aspx?ID=101/FetchCustomer" I mean I can not then pass query string.

请参见《指南》。 增 编

最佳回答

类型

当你确定<代码>类型:“POST”时,在像<编码>的查询中,形式价值并不明显。

The HTML specifications technically define the difference between "GET" and "POST" so that


former means that form data is to be encoded (by a browser) into a URL while the latter means that 

the form data is to appear within a message body. But the specifications also give the usage 

recommendation that the "GET" method should be used when the form processing is "idempotent", and in

 those cases only. As a simplification, we might say that "GET" is basically for just getting 

(retrieving) data whereas "POST" may involve anything, like storing or updating data, or ordering a 

product, or sending E-mail.

REF:

  $(document).ready(function() {
    $( #Customers ).change(function() {
      $.ajax({
        type: POST ,
        contentType: "text/html; charset=utf-8",
        data:{CustomerID:$( #Customers ).val()},
        url: "FetchCustomer.aspx",
        dataType: "html",
        success: function(data) {
          $("#CustomerDetails").html(data);
        }
      });
    });
  });
问题回答

您可以简单地删除内容类型,并指明某种类型。

  $.ajax({
    type:"POST",
    data: "CustomerID=" + $( #Customers ).val(),
    url: "FetchCustomer.aspx",
    success: function(data) {
        $("#CustomerDetails").html(data);
    }
  });




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签