Javascript cant get value from PHP variable?

Vinsens

I want make data exist checker. data.check.php:

<?php
    $nick   = mysql_real_escape_string($_POST['nick']);
    $query = mysql_query("select * from tb_user WHERE nick='$nick'");
    $nick_exist = mysql_num_rows($query);
?>

<script language="javascript" type="text/javascript">
    var nick_exist = "<?php echo $nick_exist; ?>";
</script>

and this for $POST data input.data.js

var v_nick = $('input:text[name=nick]').val();
$.post('data.check.php', {nick: v_nick} ,function() {
    if(nick_exist){
        window.alert('Choose another nick please!');
    }
});

I dont know where is the problem and my windows.alert is not running :(

thanks u

Suchit kumar

try like this get the count in php then return it to js:

NOTE: Please do not use mysql it is deprecated now start using mysqli or pdo.

data.check.php:

<?php
    $nick   = mysql_real_escape_string($_POST['nick']);
    $query = mysql_query("select * from tb_user WHERE nick='$nick'");
    $nick_exist = mysql_num_rows($query);
    echo json_encode(array('count'=> $nick_exist));//send result to javascript
?>

input.data.js

var v_nick = $('input:text[name=nick]').val();
$.post('data.check.php', {nick: v_nick} ,function(resp) {
var resp=JSON.parse(resp);
    if(resp.count){
        window.alert('Choose another nick please!');
    }
});

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Cant get jQuery variable to work

분류에서Dev

Python - Cant get minimum value

분류에서Dev

Using Ajax to get value of javascript variable?

분류에서Dev

Send variable to external PHP file from JavaScript

분류에서Dev

Cant get $_POST values from multiple forms

분류에서Dev

PHP get a value from array index

분류에서Dev

How to get a value from PHP to ExtJs?

분류에서Dev

get Selected Value in JavaScript from ztree

분류에서Dev

how to get the value of the variable from the previous seconds of a countdown using jquery?

분류에서Dev

Javascript: Snippet of code, cant get it to work (setting and reading cookies)

분류에서Dev

Pass a variable from a javascript function to another php file

분류에서Dev

Javascript passing a variable to PHP

분류에서Dev

PHP Variable in JavaScript Tag

분류에서Dev

How to get current selection value from cake php FormHelper

분류에서Dev

How to get selected radio button value onclick from php

분류에서Dev

Get data value from php array with autocomplete jquery/ajax

분류에서Dev

Get specific value from multi array JSON with PHP

분류에서Dev

How to get json value from json array using javascript

분류에서Dev

Javascript - how to get a float value from an HTML input?

분류에서Dev

How to get a string from external PHP file and set it as var in JavaScript

분류에서Dev

PHP get cookie value

분류에서Dev

Change value of variable with jquery or javascript

분류에서Dev

Javascript change value of global variable

분류에서Dev

How to get tag value from input XML where tag name is stored in a variable

분류에서Dev

How to get values for each variable from this mysql cel result using php?

분류에서Dev

php subtract variable from Array

분류에서Dev

Getting a variable from a link PHP

분류에서Dev

Accessing variable from JavaScript object

분류에서Dev

PHP multi array get value

Related 관련 기사

  1. 1

    Cant get jQuery variable to work

  2. 2

    Python - Cant get minimum value

  3. 3

    Using Ajax to get value of javascript variable?

  4. 4

    Send variable to external PHP file from JavaScript

  5. 5

    Cant get $_POST values from multiple forms

  6. 6

    PHP get a value from array index

  7. 7

    How to get a value from PHP to ExtJs?

  8. 8

    get Selected Value in JavaScript from ztree

  9. 9

    how to get the value of the variable from the previous seconds of a countdown using jquery?

  10. 10

    Javascript: Snippet of code, cant get it to work (setting and reading cookies)

  11. 11

    Pass a variable from a javascript function to another php file

  12. 12

    Javascript passing a variable to PHP

  13. 13

    PHP Variable in JavaScript Tag

  14. 14

    How to get current selection value from cake php FormHelper

  15. 15

    How to get selected radio button value onclick from php

  16. 16

    Get data value from php array with autocomplete jquery/ajax

  17. 17

    Get specific value from multi array JSON with PHP

  18. 18

    How to get json value from json array using javascript

  19. 19

    Javascript - how to get a float value from an HTML input?

  20. 20

    How to get a string from external PHP file and set it as var in JavaScript

  21. 21

    PHP get cookie value

  22. 22

    Change value of variable with jquery or javascript

  23. 23

    Javascript change value of global variable

  24. 24

    How to get tag value from input XML where tag name is stored in a variable

  25. 25

    How to get values for each variable from this mysql cel result using php?

  26. 26

    php subtract variable from Array

  27. 27

    Getting a variable from a link PHP

  28. 28

    Accessing variable from JavaScript object

  29. 29

    PHP multi array get value

뜨겁다태그

보관