javascript - jQuery detecting if php $_POST isset - Stack Overflow

I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted

I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted on page load, and if so parsing some code.

I have:

<form action="/login/register" method="post"> 
    <input type="text" value="Username" name="regName"/>
    <input type="password" value="Password" name="regPass"/>
    <input type="submit" value="Register"/>
</form>

and:

<?php

if (isset($_POST['regName']))
{
//check inputs and add account
}

?>

But i was wondering if i could check if the form had been submitted via jQuery?

Thanks.

I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted on page load, and if so parsing some code.

I have:

<form action="/login/register" method="post"> 
    <input type="text" value="Username" name="regName"/>
    <input type="password" value="Password" name="regPass"/>
    <input type="submit" value="Register"/>
</form>

and:

<?php

if (isset($_POST['regName']))
{
//check inputs and add account
}

?>

But i was wondering if i could check if the form had been submitted via jQuery?

Thanks.

Share Improve this question edited Feb 6, 2014 at 14:14 John Conde 220k99 gold badges463 silver badges502 bronze badges asked Apr 20, 2012 at 15:26 user1169601user1169601 292 silver badges5 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Just have PHP set a javascript variable to true if a POST submission was made. Then jQuery just needs to check its value.

<script type="text/Javascript">
    var was_posted = <?php echo ('POST' === $_SERVER['REQUEST_METHOD']) ? 'true' : 'false'; ?>
</script>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744755251a4591841.html

相关推荐

  • javascript - jQuery detecting if php $_POST isset - Stack Overflow

    I'm new to jQuery, and just wondering if there's a way to detect if a form has been submitted

    9小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信