3

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.

6
  • Your $_SESSION variables will be empty on page load. Do a var_dump($_POST) on your PHP page. This should show up in your alert (although console.log(result) is a lot easier. Commented Jan 3, 2014 at 9:14
  • The $_SESSION variable are not important. I want post data. Commented Jan 3, 2014 at 9:16
  • 2
    Replace all the : in your data: with =. Commented Jan 3, 2014 at 9:17
  • dont use return in insertar.php . Use echo statement Commented Jan 3, 2014 at 9:18
  • Don't edit the post to your answer. Post an answer instead. As this confuses readers and destroys the context. Edits should only contain neutral changes, unless done by the OP. Commented Jan 3, 2014 at 9:18

3 Answers 3

4

On data: replace = with : .

Example:

data:"tipo_tar=1&monto=" + "1000" 
Sign up to request clarification or add additional context in comments.

Comments

2

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" 

Comments

0

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 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.