tags:

views:

80

answers:

0

Meder made me a great code for check existing urls on a other domain with ajax.

The code is designed to check the code with a form.

At my website I have a list of links to other websites. What I want to have the outcome behind every link instead of submitting a form everytime.

This is a example of how it should look like:

* computerhulp.expertpagina.nl  (ok)
* computerproblemen.arrowsweb.nl (ok)
* pc-helpdesk.arrowsweb.nl (ok)
* windows.startkabel.nl (ok)
* ict.frieslandtotaal.nl (geen backlink)
* computer.stophier.nl  (geen backlink)
* assemblage.paginamail.nl (ok)
* computers.startpagina.be  (geen backlink)
* computer.startkabel.nl  (geen backlink)
* pc.startkabel.nl (ok)
* ilocal.nl (ok)
* DIENSTENPLEIN.NL (ok)

This is the code made by Meder.

<?php
        $query = isset($_POST['submitted']) ? true : false;
        if ( $query ) {
        $url = @file_get_contents( $_POST['site-url'] );
        if ( $url && strlen( $url ) > 0 ) {
            $checkFor = $_POST['check-for'];
            $match = preg_match( '/' . $checkFor . '/', $url );
            echo $match ? 'string (link) is found' : 'string not found';
        } else {
            echo 'could not connect to site..';
        }
        exit;
        }
    ?>
    <form action="" id="site-checker">
        <div class="field">
        <label for="site-url">Site to check:</label>
        <input id="site-url" name="site-url" value="http://jquery.com"&gt;
        </div>
        <div class="field">
        <label for="check-for">Check for:</label>
        <input id="check-for" name="check-for" value="docs.jquery.com">
        </div>
        <input type="hidden" name="submitted" value="true">
        <input type="submit">
    </form>

    <div id="result"></div>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"&gt;&lt;/script&gt;
    <script>
        $('#site-checker').submit(function(e) {
        e.preventDefault();
        $.ajax({
            url:'check.php',
            type:'POST',
            data:$('#site-checker').serialize(),
            success:function(html) {
            $('#result').html( html );
            }
        });
        });
    </script>

Any help would be great!