Click here to Skip to main content
15,895,822 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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

XML
<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
<?php
session_start();
$number = $_POST['num'];
$_SESSION['numb'] = $number;
echo $_SESSION['numb'] ;
?>
Posted

1 solution

Try this using JQuery

C#
jQuery.ajax({
        type: "POST",
        url: "Login.aspx/checkUserNameAvail",
        contentType: "application/json; charset=utf-8",
        data: "{'iuser':'" + userid + "'}",
        dataType: "xml",
        success: function (msg) {
            $(msg).find("Table").each(function () {
                var username = $(this).find('UserName').text();
                if (username != '') {
                    //window.location.replace('/iCalendar.aspx');
                    alert('This username already taken..');
                    $("#reguser").val('');
                    $("#reguser").focus();
                }
                else {
                }
            });
        },
        error: function (d) {
        }
    });
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900