Ajaxurl suddenly not defined

take a look here:

http://codex.wordpress.org/Function_Reference/wp_localize_script

First add Data in your php file

// Register the script first.

wp_register_script( 'some_handle', 'path/to/myscript.js' );

// Now we can localize the script with our data.

$translation_array = array( 'some_string' => __( 'Some string to translate' ), 'a_value' => '10' );

wp_localize_script( 'some_handle', 'object_name', $translation_array );

// The script can be enqueued now or later.
wp_enqueue_script( 'some_handle' );

?>

After that you can use the data in js

alert(object_name.some_string);

// alerts 'Some string to translate'