简体   繁体   中英

JavaScript how to Pass the variable by url?

Dear SIr i want to pass the variable by url the url is http://localhost/new_wiki/test.php?id=http://example.com

i use var first = getUrlVars()["id"]; this line of the passing the value but not working plz help me

and the test.php is like this

<!DOCTYPE html>
<html>
<head>

<link rel="stylesheet" href="css/style.css">
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.js"></script> 
</head>
<body>

<div id="article"></div>


<script type="text/javascript">


    $(document).ready(function hiren(){

var first = getUrlVars()["id"];


    $.ajax({
        type: "GET",
        url: "first",
        contentType: "application/json; charset=utf-8",
        async: false,
        dataType: "json",
        success: function (data, textStatus, jqXHR) {

        var markup = data.parse.text["*"];
        var i = $('<div></div>').html(markup);

        // remove links as they will not work
        i.find('a').each(function() { $(this).replaceWith($(this).html()); });

        // remove any references
        i.find('sup').remove();

        // remove cite error
        i.find('.mw-ext-cite-error').remove();

        $('#article').html($(i).find('p'));



        },
        error: function (errorMessage) {
        }
    });    

    });




</script>
<h1>
</h1>




</body>
</html>

but the nothing happens what is the error in it plz help me.

The JS:

   $(document).ready(function hiren(){
        // On form's submit...
        $('form').submit(function(){
            // Get input's url
            var url = $('input[name="url"]').val();

            // Do ajax's GET request
            $.ajax({
                type: "GET",
                url: url, // <-- this is the url from the input
                contentType: "application/json; charset=utf-8",
                async: false,
                dataType: "json",
                success: function (data, textStatus, jqXHR) {

                    var markup = data.parse.text["*"];
                    var i = $('<div></div>').html(markup);

                    // remove links as they will not work
                    i.find('a').each(function() { $(this).replaceWith($(this).html()); });

                    // remove any references
                    i.find('sup').remove();

                    // remove cite error
                    i.find('.mw-ext-cite-error').remove();

                    $('#article').html($(i).find('p'));



                },
                error: function (errorMessage) {
                }
            });
        });
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM