Ehsan Sadeghi
Ehsan Sadeghi

Reputation: 117

Ajax jquery Post didn't send parameters

I use this code to send a post request to another page. post call works but no parameter send to that page :

$.ajax({ type: "POST", url: "insertar.php", data:"tipo_tar:1&monto:" + "1000" + 
    "&n_m:" + "100" + "&refe:" + "100" 
    +"&usuario:" + "pcisneros01" 
    + "&email:" + "[email protected]" ,
    contentType:"application/x-www-form-urlencoded",
    success: function(result)
    {
        alert(result);
        if(result.indexOf("SMS")>=0){
            $(".centro").hide();
            $(".content-area").hide();
            $("#bodythxRecarga").show();
        }
    }
});

I am confused. I comply all rules but in destination page I don't have any post data.

Upvotes: 3

Views: 1910

Answers (3)

railsbox
railsbox

Reputation: 888

Try Like This

url: 'insertar.php',
type: 'POST',
data: {
    tipo_tar: 1,
    monto: 1000,
    n_m: 100,
    refe: 100,
    usuario: "pcisneros01",
    email: "[email protected]"
},
contentType: "application/x-www-form-urlencoded"

Upvotes: 2

Frogmouth
Frogmouth

Reputation: 1818

If you want to use "string" in data you need to replace : with =

 //your code
 data:"tipo_tar=1&monto=" + "1000" + 
      "&n_m=" + "100" + "&refe=" + "100" 
      +"&usuario=" + "pcisneros01" 
      + "&email=" + "[email protected]" ,
//your code

maybe whitout +:

//your code
 data:"tipo_tar=1&monto=1000&n_m=100&refe=100&usuario=pcisneros01&[email protected]" ,
//your code

I'm not sure but i think they are useless... if you try to create more readable code you may consider to use a plain Object for data (I like this way):

//your code
 data:{
      tipo_tar : 1,
      monto    : 1000,
      n_m      : 100,
      refe     : 100, 
      usuario  : "pcisneros01",
      email    : "[email protected]"
 },
//your code

Upvotes: 0

Mohammad Faisal Islam
Mohammad Faisal Islam

Reputation: 507

On data: replace = with : .

Example:

data:"tipo_tar=1&monto=" + "1000"

Upvotes: 4

Related Questions