Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use POST method in LOAD function of JQUERY?

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?

like image 357
armin etemadi Avatar asked Dec 05 '25 07:12

armin etemadi


2 Answers

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.

like image 104
Nick Craver Avatar answered Dec 07 '25 20:12

Nick Craver


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);
  });
like image 21
jAndy Avatar answered Dec 07 '25 21:12

jAndy