weixin_33716154 2016-08-03 16:08 采纳率: 0%
浏览 34

jQuery查询字符串类型为

i am using serialize()

Some Event trigger(assume click)

       var querydata= a=1&b=2&c=3  //jquery printing 
     $.ajax({
        url: "script",
        data: querydata,
        method: "POST",
        dataType: "text",
        success: function(data) {
          $("#counts").html(data);
            }

  });

in php do i just use the regular post method

a=htmlspecialchars($_POST["a"]); b=htmlspecialchars($_POST["b"]); and so on

or do i need to use jquery to get the string to variables and then send to data as a object array

if jquery is also an option could you tell me how i would do that im fairly new to jquery and i really want to learn it

  • 写回答

1条回答 默认 最新

  • local-host 2016-08-03 16:23
    关注

    Why bother creating a functionality that your browser+PHP provide already?? In your case, if you really have to send a raw string:

    var querydata = 'a=1&b=2&c=3';
    $.ajax({
        url: "script",
        data: querydata,
        method: "POST",
        dataType: "application/x-www-form-urlencoded",
        success: function(data) {
            $("#counts").html(data);
        }
    });
    

    You may also want to simplify:

    var querydata = {a: 1, b: 2, c: 3};
    $.post('url', querydata, function(data){
        $("#counts").html(data);
    });
    
    评论

报告相同问题?