views:

28

answers:

2

hi, 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&section=request&cid="+$("#country_id").val(), str, function(response, status, xhr) {
                  alert(response);
                });
                return false;               
        });

how can i do that?

A: 

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);
  });
jAndy
no buddy you got me wrong!!!i want to send that STR by POST method,but it isn't set by default!
armin etemadi
@armin: just add the `str` into to `data object`. I updated the post. Now you can just access `magicstr` in the data object serverside, plus, this request is `POSTED`.
jAndy
im sorry andy,the way that we access to datas in php codes is like this : for example : <?php echo $_POST['section']; ?>Is it right?
armin etemadi
@armin: it should be still right yes. In this example you can just access by `$_POST['magicstr'];`
jAndy
A: 

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.

Nick Craver