jQuery AJAXを使用して、JavaScript、PHP、およびHTMLからなる文字列をPHPから返します。jQuery Ajax複数のデータを返します
私は成功し、次のコードでこれを行うことができます。
header("Content-Type: text/html");
echo $content;
$.ajax({
type: 'POST',
url: url,
data: data,
}).done(function(result) {
}).fail(function(jqXHR, textStatus, errorThrown) {
console.log(jqXHR, textStatus, errorThrown);
});
私が今持っている問題は、私も、この文字列に沿って他のいくつかの単純な値を返すようにしたいということです。
ただし、json_encode
を使用してこれらの値の配列を送信すると、文字列が破損し、正常に処理されません。
文字列(json_encode
を除く)とjson_encode
のいくつかの値を1つの値として送信するにはどうすればよいですか? (私はしないjson_encode
私の文字列)
EDIT1:
return 'autoOpenPopup: '.!empty($options["autoOpenPopup"]) ? $this->int_to_bool($options["autoOpenPopup"]) : $this->int_to_bool(false) . PHP_EOL .';
2:
はreturn '.!isset($options["popupInit"]) ?
$playerId.' = jQuery("#'.$wrapperId.'").hap(settings);
':'
if(hasLocalStorage){
if(!localStorage.getItem("hap_popup_fixed")){
'.$playerId.' = jQuery("#'.$wrapperId.'").hap(settings);
}
}else{
'.$playerId.' = jQuery("#'.$wrapperId.'").hap(settings);
}
あなたの文字列を配列に入れたら、両方とも 'json_encode'ですか? – Chay22
私はjson_encodeを自分の文字列の上で試しました。それを配列に入れても何も変わっていないようです:http://pastie.org/10907465 – Toniq
実際に何が壊れているかを見つけるために実際のコードを投稿するべきです。 – Chay22