简体   繁体   English

从jQuery向PHP发送数据

[英]Sending data to php from jquery

have a question and I hope that you can help me with it. 有一个问题,希望您能帮助我。 I have two file frame.js and up.php . 我有两个文件frame.jsup.php frame.js take data from inputs (work correctly), and sent to up.php . frame.js从输入中获取数据(工作正常),并发送到up.php

Frame.js Frame.js

    //some code

     $.ajax({
        type : "POST",
         url: "up.php",
         data: { 
               login: login;
               pass: pass},
         success : function() {
                alert('success');
                close_frame (); 
     }
     });

up.php up.php

<?php
  echo('reg start');   //message to check that it work
  echo ('<script>alert('reg start');</script>'); // another varient to check
  if ((isset($_POST['login'])) 
 //some code
?>

SO jquery sent information to up.php. 因此,jQuery将信息发送到up.php。 But is up.php launch automatically or what I need to do to make the up.php to take the data from jquery file? 但是up.php是自动启动还是我需要做些什么才能使up.php从jquery文件中获取数据?

The up.php will run and all the data send via the ajax will be receive in the up.php将运行,并且通过ajax发送的所有数据都将在

$_POST

So basically you do need to do anything to make the data available in the php because it's already available But notice that you are not doing anything with the response (the 2 echos) so you will have to open the firebug/console in order to see the prints 因此,基本上,您确实需要做任何事情来使php中的数据可用,因为它已经可用了。但是请注意,您对响应(2个回显)没有做任何事情,因此您必须打开firebug /控制台才能看到版画

You can access any variables you send through $_POST in up.php. 您可以访问up.php中通过$_POST发送的任何变量。

You should know that jQuery has a built in function for POST ajax requests: 您应该知道jQuery对于POST ajax请求具有内置函数:

$.POST(url, data)
.done(function(response){
    alert(response);
});

You should process response from up.php in success function. 您应该在成功函数中处理来自up.php的响应。 Something like $(body).html(arguments[0]) 类似于$(body).html(arguments [0])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM