5 Replies - 2080 Views - Last Post: 06 February 2011 - 02:41 AM

#1 spikeon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-August 10

jQuery AJAX works only in chrome

Posted 04 February 2011 - 12:21 PM

What did i do wrong?
I develop in chrome, and i finally got this to work...
this morning i go to show it off and POOF, it dosen't work anymore!
This is on a wordpress install, so it had to be a little jury rigged.

Live Version: http://www.itsakstaging.com/wordpress/

Javascript:

	$('#mail').submit(function(){	
	var emails = $("#email").val();
	var phones = $("#phone").val();
	var namels = $("#namel").val();
	var namefs = $("#namef").val();
	var messages = $("#message").val();
	var actions = 'mailz';
	
	var datas = {
				action : actions,
				email : emails,
				phone : phones,
				namel : namels,
				namef : namefs,
				message : messages
			};
		$.post(
			'',
			datas,
			function( response ) {
				$('#ajax').empty();
				$('#ajax').hide();
				$('#ajax').append(response);
				$('#ajax').fadeIn(1500, function(){});
			}
		);
		return false;
	});



PHP Handler:
//wp_localize_script( 'mailz-ajax-request', 'MyAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
if($_POST['action'] == 'mailz')mail_submit_koo();
function mail_submit_koo() {
	$headers = 'From: '.$_POST['email']. "\r\n" .
    'X-Mailer: PHP/' . phpversion();
	if(mail(get_bloginfo('admin_email'), "Email from ".$_POST['namef']." ".$_POST['namel'], "Phone number: ".$_POST['phone']."\n\n ".$_POST['message'], $headers)) echo "Message Sent";
	else echo "Message Send Failed";
	die();
}



The handler is on the same page as the form that submits it
The form:
<?php $theme_options = get_option('ncubed'); ?>
<?php get_header(); ?>
	<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post();?>
        <div id='main'>
        	<div id="content" class="full">
      	  	<h1><div><?php the_title(); ?></div></h1>
						<?php the_content(__('Continue Reading...')); ?>
	   				<div id="sidebar-contact">
							<form class="anket-form" id="mail">
								<fieldset>
									<input type="hidden" name="submitMail"  id="submitMail"  value="y" />
									<input class="text" type="text" name='namef' id="namef" value="first name" />
									<input class="text" type="text" name='namel' id="namel" value="last name" />
									<input class="text" type="text" name='email' id="email" value="email address" />
									<input class="text" type="text" name='phone' id="phone" value="contact number" />
								  <textarea class="text-type" type="text" id="message" name='message' cols="" rows="">Message</textarea>
									<div class="row">
										<input class="submit" type="image" src="<?php bloginfo('template_directory');?>/images/btn-submit.gif" alt="sign up"/>
									</div>
									<div id='ajax'></div>
								</fieldset>
							</form>
						</div>
						<div id="content-contact">
							<a href="http://www.twitter.com/<?php echo $theme_options['twitter'];?>"><img src="<?php bloginfo('template_directory');?>/images/twitter-facebook.png" alt="Twitter" /></a>
							<a href="http://www.facebook.com/<?php echo $theme_options['facebook'];?>"><img src="<?php bloginfo('template_directory');?>/images/twitter-facebook2.png" alt="Facebook" /></a>
				  	</div>
	      	</div>
	      </div>
        <?php endwhile; endif; ?>
<?php get_footer(); ?>



Is This A Good Question/Topic? 0
  • +

Replies To: jQuery AJAX works only in chrome

#2 init.d.httpd  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 31
  • View blog
  • Posts: 132
  • Joined: 02-February 11

Re: jQuery AJAX works only in chrome

Posted 04 February 2011 - 12:35 PM

From what it looks like your first argument to $.post is empty. That argument should specify the file to process the post.

Also, that page is loading jQuery twice, that can cause all kinds of weird stuff to happen.
Was This Post Helpful? 0
  • +
  • -

#3 spikeon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-August 10

Re: jQuery AJAX works only in chrome

Posted 04 February 2011 - 01:29 PM

when the first element is blank it will go to the same page.

i will look into the jQuery doubling thing.
Was This Post Helpful? 0
  • +
  • -

#4 spikeon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-August 10

Re: jQuery AJAX works only in chrome

Posted 06 February 2011 - 02:28 AM

View Postspikeon, on 04 February 2011 - 01:29 PM, said:

when the first element is blank it will go to the same page.

i will look into the jQuery doubling thing.


jQuery no longer doubles, which solved a few other problems, but it didn't solve this one.
Was This Post Helpful? 0
  • +
  • -

#5 spikeon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-August 10

Re: jQuery AJAX works only in chrome

Posted 06 February 2011 - 02:35 AM

View Postspikeon, on 06 February 2011 - 02:28 AM, said:

View Postspikeon, on 04 February 2011 - 01:29 PM, said:

when the first element is blank it will go to the same page.

i will look into the jQuery doubling thing.


jQuery no longer doubles, which solved a few other problems, but it didn't solve this one.


i forgot to mention, it's as if it's not even running the script, like it's ignoring the jQuery listener for submit.
Was This Post Helpful? 0
  • +
  • -

#6 spikeon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 04-August 10

Re: jQuery AJAX works only in chrome

Posted 06 February 2011 - 02:41 AM

seconds after i posted that i refreshed it in ie, and it worked...

Here is my current file, after a couple of modifications to clean up my code.

	jQuery.noConflict();
	jQuery(document).ready(function($) {
	$('#mail').submit(function(){	
	var emails = $("#email").val();
	var phones = $("#phone").val();
	var namels = $("#namel").val();
	var namefs = $("#namef").val();
	var messages = $("#message").val();
	var actions = 'mailz';
	var datas = {
				action : actions,
				email : emails,
				phone : phones,
				namel : namels,
				namef : namefs,
				message : messages
			};
		$.post(
			$(window).attr('href'),
			datas,
			function( response ) {
				$('#ajax').empty();
				$('#ajax').hide();
				$('#ajax').append(response);
				$('#ajax').fadeIn(1500, function(){});
			}
		);
		return false;
	});
	$(document).ajaxError(function(t1,t2,t3,t4) {
  	alert('Triggered ajaxError handler. '+t4);
  	return false;
	});
});



Was This Post Helpful? 0
  • +
  • -

Page 1 of 1