Ajax запрос: < /p>
Код: Выделить всё
$( document ).ready(function() {
$("#button-addon2").click(function () {
alert("sbox = " + $("#sbox").val());
$.ajax({
url: "calcsave.php?ajtype=23&q=" + $("#sbox").val(),
context: document.body,
success: function (t) {
alert("t = " + t);
$("#calcchat").append(t);
},
});
});
});
< /code>
< /div>
< /div>
< /p>
php обрабатывает Ajax: < /p>
case 23:
//ini_set('display_errors', '1');
//ini_set('display_startup_errors', '1');
//error_reporting(E_ALL);
$q = $_GET['q'];
// $_GET['secret']=='mc-api-654'
//echo "q = " . $q . "
";
$ch = curl_init();
$url = "https://www.mathcelebrity.com/search.php?q=" . $q . "&secret=mc-api-654";
//echo "url = " . $url . "
";
$_SESSION['api'] = 1;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,2);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
//curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_HEADER, 1);
$result = curl_exec($ch);
curl_close($ch);
if (empty($result)){
echo "Nothing returned from url.";
}
else{
//echo "success";
// when we echo result, it prints full MC page with menus. Maybe try json format?
echo $result;
}
break;
, но когда он возвращается в Ajax, он показывает ошибку 400.
Я хотел бы подобрать текст и html с URL выше и отбросить его в ajax на возврате.>
Подробнее здесь: https://stackoverflow.com/questions/796 ... e-response