@ali.bayat
@Rp76
سلام
کد زیر را زدم ولی وقتی request را dd میکنم مقدار ارسال شده فرم را نشون نمیده و یکسری اطلاعات دیگه مربوط به هدرها و .... نشون میده
<script>
function showPrice(valuess) {
if (valuess == "") {
document.getElementById("order_price").innerHTML = "";
return;
}
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("order_price").innerHTML = xmlhttp.responseText;
}
};
xmlhttp.open("get", "check_price/" + valuess, true);
xmlhttp.send();
}
</script>
<div class="col-lg-4">
<div class="form-label-group position-relative has-icon-left ">
<select class="form-control select2" name="product" onchange="showPrice(this.value)">
@foreach($products as $product)
<option value="{{$product->id}}">{{$product->title}}</option>
@endforeach
</select>
@error('accounting_id') <span class="text-danger">{{$message}}</span> @enderror
</div>
<div class="text-dark rounded p-1" id="order_price"></div>
</div>
بعد ا ارسال اطلاعات این چیزیه که dd نشون میده
Illuminate\Http\Request {#43
#json: null
#convertedFiles: null
#userResolver: Closure($guard = null) {#1310
class: "Illuminate\Auth\AuthServiceProvider"
this: Illuminate\Auth\AuthServiceProvider {#141 …}
use: {
$app: Illuminate\Foundation\Application {#2 …}
}
file: "E:\Laravel-sites-design\www\hesabdari\vendor\laravel\framework\src\Illuminate\Auth\AuthServiceProvider.php"
line: "96 to 98"
}
#routeResolver: Closure() {#1319
class: "Illuminate\Routing\Router"
this: Illuminate\Routing\Router {#26 …}
use: {
$route: Illuminate\Routing\Route {#1233 …}
}
file: "E:\Laravel-sites-design\www\hesabdari\vendor\laravel\framework\src\Illuminate\Routing\Router.php"
line: "665 to 667"
}
+attributes: Symfony\Component\HttpFoundation\ParameterBag {#45
#parameters: []
}
+request: Symfony\Component\HttpFoundation\InputBag {#51
#parameters: []
}
+query: Symfony\Component\HttpFoundation\InputBag {#51}
+server: Symfony\Component\HttpFoundation\ServerBag {#47
#parameters: array:28 [
"DOCUMENT_ROOT" => "E:\Laravel-sites-design\www\hesabdari\public"
"REMOTE_ADDR" => "127.0.0.1"
"REMOTE_PORT" => "5688"
"SERVER_SOFTWARE" => "PHP 7.4.9 Development Server"
"SERVER_PROTOCOL" => "HTTP/1.1"
"SERVER_NAME" => "127.0.0.1"
"SERVER_PORT" => "8000"
"REQUEST_URI" => "/dashboard/check_price/3"
"REQUEST_METHOD" => "GET"
"SCRIPT_NAME" => "/index.php"
"SCRIPT_FILENAME" => "E:\Laravel-sites-design\www\hesabdari\public\index.php"
"PATH_INFO" => "/dashboard/check_price/3"
"PHP_SELF" => "/index.php/dashboard/check_price/3"
"HTTP_HOST" => "localhost:8000"
"HTTP_CONNECTION" => "keep-alive"
"HTTP_SEC_CH_UA" => "" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90""
"HTTP_SEC_CH_UA_MOBILE" => "?0"
"HTTP_USER_AGENT" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
"HTTP_ACCEPT" => "*/*"
"HTTP_SEC_FETCH_SITE" => "same-origin"
"HTTP_SEC_FETCH_MODE" => "cors"
"HTTP_SEC_FETCH_DEST" => "empty"
"HTTP_REFERER" => "http://localhost:8000/dashboard/work"
"HTTP_ACCEPT_ENCODING" => "gzip, deflate, br"
"HTTP_ACCEPT_LANGUAGE" => "en-US,en;q=0.9,fa;q=0.8"
"HTTP_COOKIE" => "XSRF-TOKEN=eyJpdiI6Im1jWXAyYU5zaWNBbE9QaVRhWHEwZHc9PSIsInZhbHVlIjoiQitJV0xiaEVRc2tDWFVNZHN6RTJaQVFFNExmSWZudFZBb3RxdzVhdFJQdTI4bmFCYXBZYmtzcm1tbzFxYS8vR0xaTGNmTk9hemM5dDMvbzBRUmV5K1E1UVVORWRzR0RJeUNUWkkrcmNXeDdYMWlhYmU5WUE5U3lveXFoNldIenciLCJtYWMiOiI0MDA1MDM0NTE0Y2M2M2RjZjZmM2ZmNThkNzU2NTczZDkxNjFmMzRiOTgzMjY3ODJhMjQ3MDI3MDY2MWJkMTAzIn0%3D; laravel_session=eyJpdiI6IkN4ME9RUTl0SGVQNWtORjlRdjZTcUE9PSIsInZhbHVlIjoiNVAwNmdvdHdVWjlWbU9GaDEydXlUczdudmpCOHd2NTgvTi9uV1FkbkxqUzVaTVpFOXNNTlNUZUdva1YvSUZqRjB4OSt1T3RTaFo1aUcyOWFwQkgwaUcweTJwTE80MFdpVmJENG91dCt2Nm1UZmovelZ6aDV5M2Jma3JORkNDVisiLCJtYWMiOiI5MjYyNmM0Mzk5Nzg0NmZiNDllN2U4ZDc4N2NjNDMyNWU1YWI1MzY2OWMzODAwN2YwM2IyYWJjNzI4MWRiYTc3In0%3D"
"REQUEST_TIME_FLOAT" => 1620727475.4325
"REQUEST_TIME" => 1620727475
]
}
+files: Symfony\Component\HttpFoundation\FileBag {#48
#parameters: []
}
+cookies: Symfony\Component\HttpFoundation\InputBag {#46
#parameters: array:2 [
"XSRF-TOKEN" => "SpJdQJMGIC5ZFmQpMDksKiecq4WAxMgSGbh2h6Wg"
"laravel_session" => "6Jd4zg6K4OsLCJPC5Ze223dRwQc6ikmUpIX4COxg"
]
}
+headers: Symfony\Component\HttpFoundation\HeaderBag {#49
#headers: array:13 [
"host" => array:1 [
0 => "localhost:8000"
]
"connection" => array:1 [
0 => "keep-alive"
]
"sec-ch-ua" => array:1 [
0 => "" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90""
]
"sec-ch-ua-mobile" => array:1 [
0 => "?0"
]
"user-agent" => array:1 [
0 => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36"
]
"accept" => array:1 [
0 => "*/*"
]
"sec-fetch-site" => array:1 [
0 => "same-origin"
]
"sec-fetch-mode" => array:1 [
0 => "cors"
]
"sec-fetch-dest" => array:1 [
0 => "empty"
]
"referer" => array:1 [
0 => "http://localhost:8000/dashboard/work"
]
"accept-encoding" => array:1 [
0 => "gzip, deflate, br"
]
"accept-language" => array:1 [
0 => "en-US,en;q=0.9,fa;q=0.8"
]
"cookie" => array:1 [
0 => "XSRF-TOKEN=eyJpdiI6Im1jWXAyYU5zaWNBbE9QaVRhWHEwZHc9PSIsInZhbHVlIjoiQitJV0xiaEVRc2tDWFVNZHN6RTJaQVFFNExmSWZudFZBb3RxdzVhdFJQdTI4bmFCYXBZYmtzcm1tbzFxYS8vR0xaTGNmTk9hemM5dDMvbzBRUmV5K1E1UVVORWRzR0RJeUNUWkkrcmNXeDdYMWlhYmU5WUE5U3lveXFoNldIenciLCJtYWMiOiI0MDA1MDM0NTE0Y2M2M2RjZjZmM2ZmNThkNzU2NTczZDkxNjFmMzRiOTgzMjY3ODJhMjQ3MDI3MDY2MWJkMTAzIn0%3D; laravel_session=eyJpdiI6IkN4ME9RUTl0SGVQNWtORjlRdjZTcUE9PSIsInZhbHVlIjoiNVAwNmdvdHdVWjlWbU9GaDEydXlUczdudmpCOHd2NTgvTi9uV1FkbkxqUzVaTVpFOXNNTlNUZUdva1YvSUZqRjB4OSt1T3RTaFo1aUcyOWFwQkgwaUcweTJwTE80MFdpVmJENG91dCt2Nm1UZmovelZ6aDV5M2Jma3JORkNDVisiLCJtYWMiOiI5MjYyNmM0Mzk5Nzg0NmZiNDllN2U4ZDc4N2NjNDMyNWU1YWI1MzY2OWMzODAwN2YwM2IyYWJjNzI4MWRiYTc3In0%3D"
]
]
#cacheControl: []
}
#content: null
#languages: null
#charsets: null
#encodings: null
#acceptableContentTypes: null
#pathInfo: "/dashboard/check_price/3"
#requestUri: "/dashboard/check_price/3"
#baseUrl: ""
#basePath: null
#method: "GET"
#format: null
#session: Illuminate\Session\Store {#1395
#id: "6Jd4zg6K4OsLCJPC5Ze223dRwQc6ikmUpIX4COxg"
#name: "laravel_session"
#attributes: array:5 [
"_token" => "SpJdQJMGIC5ZFmQpMDksKiecq4WAxMgSGbh2h6Wg"
"url" => []
"_previous" => array:1 [
"url" => "http://localhost:8000/dashboard/check_price/2"
]
"_flash" => array:2 [
"old" => []
"new" => []
]
"login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 2
]
#handler: Illuminate\Session\FileSessionHandler {#1394
#files: Illuminate\Filesystem\Filesystem {#163}
#path: "E:\Laravel-sites-design\www\hesabdari\storage\framework/sessions"
#minutes: "120"
}
#started: true
}
#locale: null
#defaultLocale: "en"
-preferredFormat: null
-isHostValid: true
-isForwardedValid: true
-isSafeContentPreferred: null
basePath: ""
format: "html"
}
سلام دوباره!
خب دقیقا مشکل از route شما هست
توی route گفتید {check_price} متغیر هست ولی توی کنترلر خودتون اون رو ارسال نکردید
public function check_price(Request $request,$check_price)
{
dd([$request,$check_price]);
}
این رو تست کنی فکر کنم حل بشه قضیه
فقط توی متد مربوطه یه dd از request برای تست میگیرم
use Illuminate\Http\Request;
class WorkController extends Controller
{
public function check_price(Request $request)
{
dd($request);
}
}
خب پس مشکل از js هست که زدی
داری اشتباه پارامتر ارسال میکنی البته اینطور که من دیدم
$.get(`check_price?rp=${valuess}`,function(data){
console.log(data);
})
@Rp76
سلام دوست عزیز
خب کدی که دادین که اون قسمت ?rp= کلا توی لاراول خطا میده 404 و من به صورت زیر تغییر دادم بازم مثل کد اولم هست
و وقتی توی کنترلر $request->product را میگیرم کلا null میده مقدارشو
<script>
function showPrice(valuess) {
$.get(`check_price/${valuess}`, function (data) {
document.getElementById("order_price").innerHTML = data;
})
}
</script>
خب این کد بالا چیزی ارسال نمیکنه
این کد رو هم تست کن و بعد route رو هم برام بفرست حس میکنم Route رو اشتباه نوشتی
<script>
function showPrice(valuess) {
$.get(`check_price/${valuess}?id=1`, function (data) {
document.getElementById("order_price").innerHTML = data;
})
}
</script>
چون این route که میگی 404 میده رو من بار ها استفاده کردم.
@Rp76
این روت من
Route::get('/check_price/{check_price}', [WorkController::class, 'check_price'])->name('check_price');
اطلاعات توی قسمت parameters و کلید "PATH_INFO" نمایش داده میشه ولی به صورت رشته آدرس نشون میده
توی پست اول که گذاشتم ببینی آیدی 3 را پاس میده ولی به صورت آدرسه
"PATH_INFO" => "/dashboard/check_price/3"
سلام دوباره!
خب دقیقا مشکل از route شما هست
توی route گفتید {check_price} متغیر هست ولی توی کنترلر خودتون اون رو ارسال نکردید
public function check_price(Request $request,$check_price)
{
dd([$request,$check_price]);
}
این رو تست کنی فکر کنم حل بشه قضیه
آیا مایل به ارسال نوتیفیکیشن و اخبار از طرف راکت هستید ؟