亲爱的SIr我想通过url传递变量 网址为http://localhost/new_wiki/test.php?id=http://example.com
我使用var first = getUrlVars()[" id"];这行传递值但不工作PLZ帮助我
并且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>
但是没有任何反应是什么错误,它帮助我。
答案 0 :(得分:0)
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) {
}
});
});
});