Вы неправильно загрузили json - но даже если бы это было правильно, вы не смогли бы протестировать, используя print_r($_POST)
( read why here ). Вместо этого на вашей второй странице вы можете набрать входящий запрос, используя file_get_contents("php://input")
, который будет содержать POSTed json. Чтобы просмотреть полученные данные в более читаемом формате, попробуйте следующее:
echo ''.print_r(json_decode(file_get_contents("php://input")),1).'
';
В вашем коде вы указываете Content-Type:application/json
, но вы не кодируете json все данные POST - только значение поля «POST» клиента. Вместо этого сделайте что-то вроде этого:
$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "$result
";
Sidenote: вы можете использовать стороннюю библиотеку вместо непосредственного взаимодействия с Shopify API.
Может быть, так:
document.getElementsByClassName('contacts_modal_search_field')[0].value = "test";
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="Search" ng-model="search.query" autocomplete="off" style="">
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>
Используйте document.getElementById("id").value = "yourvalue"
или document.getElementsByClassName("yourclass")[index].value = "yourvalue"
.
Используя id
:
Enter text to be the value of the second input field:<br/>
<input type="text" id="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<input type="text" id="result"/>
<script>
function changeValue(){
document.getElementById("result").value = document.getElementById("text").value;
}
</script>
Используя class
:
Enter text to be the value of the second input field:<br/>
<input type="text" class="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<input type="text" class="result"/>
<script>
function changeValue(){
document.getElementsByClassName("result")[0].value = document.getElementsByClassName("text")[0].value;
}
</script>
Для вашего кода:
Enter text to be the value of the search input field:<br/>
<input type="text" class="text"/>
<br/>
<input type="button" onClick="changeValue()" value="Change Value"/>
<p/>
<script>
function changeValue(){
document.getElementsByClassName("form-control")[0].value = document.getElementsByClassName("text")[0].value;
}
</script>
<hr>
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="Search" ng-model="search.query" autocomplete="off" style="">
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>
Изменить значение поля ввода окна при загрузке окна (с помощью window.onload
):
<script>
window.onload = function(){
document.getElementsByClassName("form-control")[0].value = "your value";
}
</script>
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="" ng-model="search.query" autocomplete="off" style="">
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>
вы можете ввести текстовое поле с помощью java-скрипта.
<div class="contacts_modal_search">
<input class="form-control contacts_modal_search_field no_outline ng-pristine ng-valid ng-empty ng-touched" my-focused="" type="search" placeholder="Search" ng-model="search.query" autocomplete="off" style="" id='contacts_modal_search_field'>
<a class="im_dialogs_search_clear tg_search_clear ng-hide" ng-click="search.query = ''" ng-show="search.query.length" style="">
<i class="icon icon-search-clear"></i>
</a>
</div>
<script>
window.onload=function(){
//by Class name
document.getElementsByClassName('contacts_modal_search_field')[0].value='Something'
//by Id
document.getElementById('contacts_modal_search_field')[0].value='Something' //if 'contacts_modal_search_field' is your input box ID
//By Tag name
document.getElementsByTagName('input')[0].value='Something'
}
</script>