0

I created a simple test for a function to grab the video id from a youtube url and echo it out. It works fine as is but when I introduce jQuery code in the mix I receive this error NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument. The error is commenting the jquery.js file on line 7071. I have no idea what to do or what is exactly causing this. The code is below.

First File

<script src="http://code.jquery.com/jquery-latest.js"></script>

<input type="text" id="url" />

<input type="button" id="press" value="click" />

<div id="return"></div>

<script type="text/javascript" >

    $('#press').click(function () {

$('#url').val();

    $.post('ajax_youtube.php', {url:url}, function(data) {

        $('#return').html(data);

    }); 

    });

</script>

Here is the ajax_youtube.php file

<?php

function get_youtube_url($text) {

$text = preg_replace('~https?://(?:[0-9A-Z-]+\.)?(?:youtu\.be/| youtube\.com\S*[^\w
\-\s])([\w\-]{11})(?=[^\w\-]|$)(?![?=&+%\w]*(?:[\'"][^<>]*>| </a>))[?=&+%\w-]*~ix', 
'$1', $text);

echo $text;

}

$url = $_POST['url'];

get_youtube_url($url);

?>
2
  • 3
    I think this $('#url').val(); should be var url = $('#url').val(); Commented Sep 19, 2012 at 6:59
  • Thanks. I feel silly. Post it as the answer since you were the first one to answer and I'll give you credit. Commented Sep 19, 2012 at 7:01

1 Answer 1

3

You forgot to assign url to a value, $('#url').val(); should be var url = $('#url').val();

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.