PHP関数を呼び出すクライアント側のJavascriptスクリプトがあり、URLでfile_get_contentsを呼び出します。次に、これはJavascriptスクリプトに返送されます。このスクリプトは、返されたHTMLを解析することになっています。
私は現在、次のようにスクリプトを実装しています。
PHP:
<?php
if (isset($_GET['url'])) {
$myURL=$_GET['url'];
$homepage = file_get_contents($myURL);
echo $homepage;
}
?>
Javascript:
$.ajax({
url: 'wp-content/plugins/InContext/php/get_url.php',
async: false,
data: { url: buildUrl(dataType,ticker,source) },
success: function(output) {
pageHtml = output;
alert(pageHtml);
}
});
var divWrapper = $('<div></div>');
divWrapper.html(pageHtml);
ただし、これにより、次のようなエラーが発生します。
Uncaught TypeError: Cannot read property 'Event' of undefined.
私はここで何が間違っているのですか?pageHtmlを文字列などに変換してjQueryを使用して解析する必要がありますか?