[英]Is it the good way to post variable with ajax processing
I'm trying to post
a pseudo with ajax
like in the title , i think actually with my code i send no informations to my php
file. 我想
post
一个伪ajax
一样的称号,其实我觉得我的代码我没有信息发送到我php
文件。
so this is the code : 所以这是代码:
$('#send').click(function(){ var pseudo = $('#psd').val(); }); function recuppoint() { $.post('point.php',{pseudo: pseudo} ,function(data) { console.log('['+data + ']'); $('.infos2').html(data); }); } setInterval(recuppoint, 1000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form method="post" id="logForm" action=""> <div class="field"> <label class="field-label" for="mailconnect">Votre mail</label> <input class="field-input"type="email" name="mailconnect" id="email" /> </div> <div class="field" id="psd"> <label class="field-label" for="client">pseudo client</label> <input class="field-input" type="text" name="pseudo" id="pseudo" /> </div> <div class="field"> <label class="field-label" for="mdpconnect">mdp</label> <input class="field-input" type="password" name="mdpconnect" id="password" /> </div> <button id="send" class="send"name="formsubscribe">begin</button> </form> <div> <div id="infos" class="infos" align="center"> </div> <div id="infos2" class="infos2" align="center"> </div> </div>
So guys how can i solve the problem with the var pseudo ? 那么伙计们我该如何解决var pseudo问题呢?
thank you 谢谢
Your div element with id "psd", doesnt have value. 您ID为“ psd”的div元素没有值。 If you want to send html use .html();
如果要发送html,请使用.html();。 If you want to get only input values so try some like this:
如果只想获取输入值,请尝试如下操作:
var x = $('input[name=nameOfInput]').val();
Then you should send it with ajax. 然后,您应该使用ajax发送它。
your ajax
call should be like this . 你的
ajax
调用应该是这样的。
you can not access the input
field with its parent id as you did $('#psd').val();
您不能像
$('#psd').val();
那样使用其父ID访问input
字段$('#psd').val();
but you can access it value with its id itself like this 但是您可以像这样使用其ID本身访问它的值
<input class="field-input" type="text" name="pseudo" id="pseudo" />
$('#send').on('click', function(){ var pseudo = $('#pseudo').val(); $.ajax({ url:'point.php', type:'POST', data:{ ele: pseudo}, success:function(data){ $('.infos2').html(data); } }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <form method="post" id="logForm" action=""> <div class="field"> <label class="field-label" for="mailconnect">Votre mail</label> <input class="field-input"type="email" name="mailconnect" id="email" /> </div> <div class="field" id="psd"> <label class="field-label" for="client">pseudo client</label> <input class="field-input" type="text" name="pseudo" id="pseudo" /> </div> <div class="field"> <label class="field-label" for="mdpconnect">mdp</label> <input class="field-input" type="password" name="mdpconnect" id="password" /> </div> <button id="send" class="send"name="formsubscribe">begin</button> </form> <div> <div id="infos" class="infos" align="center"> </div> <div id="infos2" class="infos2" align="center"> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.