Ajax jquery Post没有发送参数

时间:2022-12-08 20:07:13

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:" + "esadeghi@gmail.com" ,
    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.

我很困惑。我遵守所有规则但在目的地页面中我没有任何发布数据。

3 个解决方案

#1


4  

On data: replace = with : .

关于数据:replace = with :.

Example:

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

#2


2  

Try Like This

尝试这样

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

#3


0  

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

如果要在数据中使用“string”,则需要替换:with =

 //your code
 data:"tipo_tar=1&monto=" + "1000" + 
      "&n_m=" + "100" + "&refe=" + "100" 
      +"&usuario=" + "pcisneros01" 
      + "&email=" + "esadeghi@gmail.com" ,
//your code

maybe whitout +:

也许whitout +:

//your code
 data:"tipo_tar=1&monto=1000&n_m=100&refe=100&usuario=pcisneros01&email=esadeghi@gmail.com" ,
//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):

我不确定,但我认为它们没用......如果你试图创建更可读的代码,你可以考虑使用普通的Object作为数据(我喜欢这样):

//your code
 data:{
      tipo_tar : 1,
      monto    : 1000,
      n_m      : 100,
      refe     : 100, 
      usuario  : "pcisneros01",
      email    : "esadeghi@gmail.com"
 },
//your code

#1


4  

On data: replace = with : .

关于数据:replace = with :.

Example:

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

#2


2  

Try Like This

尝试这样

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

#3


0  

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

如果要在数据中使用“string”,则需要替换:with =

 //your code
 data:"tipo_tar=1&monto=" + "1000" + 
      "&n_m=" + "100" + "&refe=" + "100" 
      +"&usuario=" + "pcisneros01" 
      + "&email=" + "esadeghi@gmail.com" ,
//your code

maybe whitout +:

也许whitout +:

//your code
 data:"tipo_tar=1&monto=1000&n_m=100&refe=100&usuario=pcisneros01&email=esadeghi@gmail.com" ,
//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):

我不确定,但我认为它们没用......如果你试图创建更可读的代码,你可以考虑使用普通的Object作为数据(我喜欢这样):

//your code
 data:{
      tipo_tar : 1,
      monto    : 1000,
      n_m      : 100,
      refe     : 100, 
      usuario  : "pcisneros01",
      email    : "esadeghi@gmail.com"
 },
//your code