Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ajax problems in chrome

Status
Not open for further replies.

zura

Technical User
Sep 20, 2011
23
GE
Hi guys.
I have problem with this script in chrome and cant solve it.
It works in any another browser very well, but not in chrome.
Thanks for help.

mail = $("#mail").val();
$.ajax({
url: "conect.php",
type: "POST",
data: "mail=" + mail,
cache: false,
success: function(response){
if (response == "yes"){
$parentTag.addClass('error').append($error.clone().text("this mail is used..."));
show();
}
else $formId.submit();
}
})

<!-- conect.php -->
<?
$mail=$_POST['mail'];

$queryuser=mysql_query("SELECT * FROM table WHERE mail='$mail'",$db1);
$checkuser=mysql_num_rows($queryuser);
if($checkuser != 0)
{ echo "no"; }
else {
echo "yes";
}
?>
 
when you say that it does not work, what is it that does not work?

are you able to send the ajax request?
do you get a response?
is the response what you anticipate?
is your problem that the text node does not get appended to $parentTag in the event that the response is "yes"?
is your problem that the form $formID does not submit in the event that the response is anything other than "yes"?

unless you tell us what's wrong, it's terribly difficult to help you.

as it happens I would improve the script slightly by ensuring that that the response is treated as json. do this by adding dataType: 'json' to the ajax options.

in your php script do this

Code:
<?php
$mail=$_POST['mail'];
$queryuser=@mysql_query(sprintf("SELECT count(*) FROM table WHERE mail='%s'", mysql_real_escape_string($mail)),$db1);
if($queryuser == false){
	die(mysql_error());
}
$row = mysql_fetch_array($queryuser) or die(mysql_error());
if($row[0] > 0):
	$result = "yes";
} else {
	$result = "no";
}
echo json_encode($result);
die;
?>

you might think of changing the structure into an array where you can report the errors to the client for debugging purposes.

note the important change in the php code to guard against sql injection.
 
jpadie.
It not makes response.
I think problems is in ajax.
 
i wonder what you mean by 'in ajax'.

how are you determining that there is no response?
have you attempted to test the response by manually submitting a form?
have you looked at the tcp traces/network traffic to see whether your browser is trying to communicate?
have you installed a debugging tool into chrome to take a look at what is going on? or even use the native console?
 
To jpadie.
In "Network" tab I have:
Capture.PNG
 
you have not put the full screen shot in so I am having to guess here.

most likely is that you have misspelled the url in the ajax command. or possibly failed fully to point to the right resource - try a fully qualified url.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top