テキストエリアからデータを送信する簡単なjQuery関数を記述しました。スクリプトは計算結果を返します。 recievedDataが定義されていないというエラーが表示されます。 firebugでデバッグすると、私は応答を見ることができます。jQueryを使用したPHPスクリプトとの通信
ここに私のjQuery関数があります。
$('#submitButton').click(
function(evt){
userCode = $('#answer').val();
$.ajax({
type : 'POST',
url : 'scripts/php/check_answer.php',
data : 'code=' + userCode,
dataType : 'text',
success : alert(recievedData)
});
evt.preventDefault;
});
そして、これがrecievedDataが定義されていないだってそれだPHPスクリプト
<?php
//sample string, to be taken as input from the user program.
$str = $_POST['code'];
//the array with the weights
$patterns = array (
'/[:space]/' => 0, //whitespaces are free; need to add spaces too
'/[a-zA-Z]/' => 10, //characters
'/[0-9]/' => 500, //digits
'/[\+\-\/\*\%]/' => 10000, //arithmetic operators
'/[\<\>]/' => 5000, //relational operators
'/[\^\~\|\&]/' => 1000 , //bitwise operators
'/[\=]/' => 250, //assignment operator
'[\#]' => 100000 //No Macros
);
//default weight for characters not found is set here
$default_weight = 55;
$weight_total = 0;
foreach ($patterns as $pattern => $weight)
{
$match_found = preg_match_all ($pattern, $str, $match);
if($match_found)
{
$weight_total += $weight * $match_found;
}
else
{
//this part needs to be fixed
$weight_total += $default_weight;
}
}
echo $weight_total;
?>
に投稿するもう一つの方法です。 ;-)サイドノート:アプリケーションでその名前を使用する場合は、「receivedData」というスペルミールをおすすめします。私たちのアプリケーションで間違って「受け取った」と綴られていて、何年も私たちを悩ませました!冗談抜き! (下位互換性を持っていなければならなかった) –