[英]JavaScript how to Pass the variable by url?
亲爱的先生,我想通过url传递变量,url是http://localhost/new_wiki/test.php?id = http://example.com
我使用var first = getUrlVars()[“ id”]; 这行传递值但不起作用请帮助我
和test.php是这样的
<!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>
但是什么也没发生,请问有什么错误请帮助我。
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) {
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.