Hello,
I am doing simple Jquery ajax post to php and I am very new to three languages. Any suggestion or guidance.
I have two iframes
1. iframe 1 is Navigation menu(loaded with flash menu).
<iframe name=”menu”/>
2. iframe 2 is load the web page.
<iframe name=”page_load”/>
When I click the navigation menu the corresponding web page loaded.
In one part, when I clicked the navigation “menu” the login_reg.php page open in page_load.
The login_reg page has two parts of form,
1. In one, registration process is done
<form id=”registration”/>
2. In another, login is done.
<form id=”login_form”/>
When I submit the login_form, it check the login and password.if it success, both parent iframes should be reloaded by corresponding src attribute,
MY problem:
- But sometimes it getting refresh without any changes and.
- Mozilla, safari it doesn’t works and just page is get refreshed.
My Jquery and ajax script:
$(document).ready(function(){
$("form#login_form").submit(function() {
alert('this method is called');
var user_id=$('#user_id').val();
var p_word=$('#p_word').val();
if(user_id.length >= 4 && p_word.length>=4)
{
$.ajax({
type: "POST",
url: "login-exec.php",
data: "user_id="+ user_id + "&p_word="+p_word,
success: function(msg){
alert('it entered the message');
if(msg == 'OK')
{
parent.load_right('pub@lic_profile/@_profile/all_@_all/flashmo_203_modified.swf');
parent.load_left('pub@lic_profile/@_profile/all_@_all/horizontal_menu/flashmo_114_horizontal_03.swf');
}
else if(msg=='NOT')
{
alert('the message is alert is not OK');
}
}
});
}
else
{
$("#status1").html('<font color="red">The username should have at least <strong>4</strong> characters.</font>');
$("#username").removeClass('object_ok');
$("#username").addClass("object_error");
}
});
PHP script:
<?php
include_once dirname(__FILE__).'/sql.php';
$link = mysql_connect(server, user, password);
if(!$link)
{
die('Failed to connect to server: ' . mysql_error());
}
$db = mysql_select_db(DB_CATALOG);
if(!$db) {
die("Unable to select database");
}
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
$username = clean($_POST['user_id']);
$password = clean($_POST['p_word']);
$qry="select * from customer_se where username='".$username."' and password='".md5($password)."'";
$result=mysql_query($qry);
if(mysql_num_rows($result))
{
echo 'OK';
}
else
{
echo 'NOT';
}
?>
Thanks in advance,
With Regards,
Eswaran Saravanan,
University west,
Sweden