Posts o[js+php] elementary - ajax json, php call
Post
Cancel

o[js+php] elementary - ajax json, php call

indicators - http://zanstra.home.xs4all.nl/picks/progress.html

I have an inputbox when it length is > 9 needed to validate for double record..

the input element

1
2
3
4
<div class='form-group'>
	<label>Telephone :</label>![](img/mini_indicator.gif)
	<input name='telephone' class='form-control' placeholder='Telephone'>
</div>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
		$('[name=telephone]').on('input',function(e){
			if ($(this).val().length>9)
			{
			 	$("#tel_indicator").show();

					$.ajax({
						url : 'tab_leads_details_ask_4_double.php',
						dataType : 'json',
						type : 'POST',
						data : {
							"tel" : $(this).val()
						},
			            success : function(data) {
			            	$("#tel_indicator").hide();

			            	if (data=="error")
			            		alert("Error - when checking for double records via telephone");
			            	else if (data.rec_count>0)
			            	{
								$("[name=telephone]").css({ 'background': 'rgba(255, 0, 0, 0.3)' });
							}
							else 
								$("[name=telephone]").css({ 'background': 'white' });
						}
					});
			}
			else 
				$("[name=telephone]").css({ 'background': 'white' });
		});
1
2
3
4
//tab_leads_details_ask_4_double.php
<?php require_once="" ('config.php');="" if(!isset($_post["tel"])){="" echo="" json_encode("error");="" return;="" }="" $db="connect();" $r="getScalar($db," select"="" count(client_id)="" from="" clients="" where="" telephone="?" ,array($_post["tel"]));"="" echo="" json_encode(array("rec_count"=""?>$r));

?>

1-length = 9 2-length = 10 -> ajax call php 3-php returns > 0

origin - http://www.pipiscrew.com/?p=2575 js-elementary-ajax-json-php-call

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags