开发者

how to use POST method in LOAD function of JQUERY?

开发者 https://www.devze.com 2023-01-07 14:12 出处:网络
i want to load JUST one part of my document,i had to use LOAD function bcause of this,so i tried this function.but i have a problem,i want to set method of this function to POST.i read in jquery manua

i want to load JUST one part of my document,i had to use LOAD function bcause of this,so i tried this function.but i have a problem,i want to set method of this function to POST.i read in jquery manual that this function is using GET method by default,but if your data is an object it will use POST method.i dont know how to do that?i mean using an object in data list!

here is my code :

$("#form_next").live("click", function(event){

                var str = $("#form").serialize();

                $("#form").load("form.php?ajax=y&s开发者_JAVA百科ection=request&cid="+$("#country_id").val(), str, function(response, status, xhr) {
                  alert(response);
                });
                return false;               
        });

how can i do that?


You can make a simple tweak here, use .serializeArray() instead of .serialize(), like this:

$("#form_next").live("click", function(event){
  var obj = $("#form").serializeArray();
  $("#form").load("form.php?ajax=y&section=request&cid="+$("#country_id").val(), obj, function(response, status, xhr) {
    alert(response);
  });
  return false;               
});

This triggers the same logic as passing the data as an object (since you are, specifically an array), and will cause a POST instead of a GET like you want.


Well, you actually already answered your question.

$("#form").load("form.php", {
     ajax:     y,
     section:  request,
     cid:      $("#country_id").val(),
     magicstr: str
  }, function(response, status, xhr) {
              alert(response);
  });
0

精彩评论

暂无评论...
验证码 换一张
取 消