无法通过Ajax将数据发送到PHP页面 [英] Unable to send data via Ajax to a PHP page

查看:176
本文介绍了无法通过Ajax将数据发送到PHP页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过ajax将变量 number 的值发送到PHP脚本。但PHP脚本不会在浏览器上打开时打印所需的输出。试过但在这里找不到什么错。

任何指针?



index.html



 <  按钮    type   =  submit    class   =  btn btn-success    id     ='  first'    onclick   ='  process() ;' > 提交<   /按钮 >  

< script >

var number = 0;

函数进程()
{
number ++;

var xhr;

if(window.XMLHttpRequest){
xhr = new XMLHttpRequest();
} else if(window.ActiveXObject){
xhr = new ActiveXObject(Microsoft.XMLHTTP);
}

var data =num =+ number;
xhr.open(POST,index.php,true);
xhr.send(数据);

< / script >





index.php



 <?php  
session_start();
$ number = $ _POST [' num ];
$ _SESSION [' numb'] = $数目;
echo $ _SESSION [' numb'];
?>

解决方案

数字 =


_POST [' num'];

_SESSION [' numb'] =

I'm trying to send the value of a variable number via ajax to a PHP script. But the PHP script is not printing the desired output on opening on a browser. Tried but couldn't find whats wrong here.
Any pointers ?

index.html

<button type="submit" class="btn btn-success" id = 'first' onclick='process();'>Submit</button>

<script>

var number = 0;

function process()
{
number++;

var xhr;

 if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
} else if (window.ActiveXObject) {
    xhr = new ActiveXObject("Microsoft.XMLHTTP");
}

var data = "num=" + number;
xhr.open("POST", "index.php", true);
xhr.send(data);

</script>



index.php

<?php
session_start();
$number = $_POST['num'];
$_SESSION['numb'] = $number;
echo $_SESSION['numb'] ;
?>

解决方案

number =


_POST['num'];


_SESSION['numb'] =


这篇关于无法通过Ajax将数据发送到PHP页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆