I take over someone's job and find out their code.
It's a mix of reactjs and jQuery.
The goal is to look for information in the database and insert it in a drop-down list.
With Google Chrome, the drop-down list is fed
but not with Firefox :
With Chrome's console (console.log($("[name='liste_horaire']").length);)
I see 1 and 0 with Firefox
Here is the reactjs code (which I found)
var layout = {};
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Container"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Container"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("h2", null, "2020-2021 2\xE8me quadrimestre 31/03/2020 MA Bloc 1")), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", {
className: "form-group row"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("label", {
className: "col-md-4 col-form-label text-md-right"
}, "Liste des horaires"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("div", {
className: "col-md-6"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("select", {
onChange: this.handleChange,
type: "text",
className: "form-control selectpicker",
name: "liste_horaire"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("option", {
value: "test",
defaultValue: true
}, "1"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement("option", {
value: "test2"
}, "2")))), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Container"], {
className: "custom-home-table"
}, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(react_bootstrap__WEBPACK_IMPORTED_MODULE_3__["Button"], {
onClick: this.onAddItem
}, "Ajouter un evenement"), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0___default.a.createElement(ResponsiveReactGridLayout, _extends({
onBreakpointChange: this.onBreakpointChange
}, this.props, {
/* layout={layout}
onLayoutChange={( layout) =>
this.onLayoutChange(layout)
}*/
onDragStop: this.onDragStop,
onResizeStop: this.onResizeStop
}), daysLayout.map(function (item) {
return createDayElement(item);
}), layout1.map(function (item) {
return createStaticElement(item);
}), lodash__WEBPACK_IMPORTED_MODULE_2___default.a.map(this.state.items, function (el) {
return _this2.createElement(el);
}))));
}
}]);
and the jQuery code
$.ajax({
type: 'get',
url: 'getAllHoraires',
dataType: 'json',
success: function success(data) {
// console.log('getAllHoraires:');
// console.log(data);
console.log($("[name='liste_horaire']").length);
$("[name='liste_horaire']").empty(); //je vide la ld avant de la remplir, autrement doublon
$.each(data, function (idx, value) //parcours du retour php quie est au format json
{
//ajoute le id et le nom de l'horaire ?� la liste deroulante
$("[name='liste_horaire']").append($('<option/>').val(value.id).html(value.name + ' ' + value.id));
console.log(value.idx);
console.log(value.name);
}); //fin du each
},
error: function error(_error) {
alert("dans erreur ajax get liste horaire ");
console.log(_error);
}
}); //https://github.com/STRML/react-grid-layout/blob/master/test/test-hook.jsx
//https://github.com/STRML/react-grid-layout/blob/master/test/examples/6-dynamic-add-remove.jsx
//we use external class and function
//call external function makeLayout with as argument the class AddRemoveLayout
Object(_makeLayout__WEBPACK_IMPORTED_MODULE_0__["makeLayout"])(_AddRemoveLayout__WEBPACK_IMPORTED_MODULE_1__["AddRemoveLayout"]); //getHoraire
as well as the PHP code (Laravel 7) :
public function getAllHoraires()
{
$horaires = Horaire::get();
/* $quadrimestres = Quadrimestre::latest()->get();
$years = Year::latest()->get();*/
return response()->json($horaires);
}
Could you please tell me how I can solve this problem and at the same time improve the code?
I found the solution :
Before, I called my Object after the Ajax, now, I call it before and it works :
makeLayout(AddRemoveLayout);
$.ajax({
type: 'get',
url: 'getAllHoraires',
dataType: 'json',
success: function(data)
Hope it will help others...
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.
PHP (from the English Hypertext Preprocessor - hypertext preprocessor) is a scripting programming language for developing web applications. Supported by most hosting providers, it is one of the most popular tools for creating dynamic websites.
The PHP scripting language has gained wide popularity due to its processing speed, simplicity, cross-platform, functionality and distribution of source codes under its own license.
https://www.php.net/
Laravel is a free open source PHP framework that came out in 2011. Since then, it has been able to become the framework of choice for web developers. One of the main reasons for this is that Laravel makes it easier, faster, and safer to develop complex web applications than any other framework.
https://laravel.com/
React is currently the leader in JavaScript UI frameworks. First, the Facebook developers started working on this to make their job easier. An app called Facebook Ads grew very quickly, which meant complex management and support. As a result, the team began to create a structure that would help them with efficiency. They had an early prototype before 2011, and two years later, the framework was open source and available to the public. It is currently used by many business giants: AirBNB, PayPal, Netflix, etc.
https://reactjs.org/
JQuery is arguably the most popular JavaScript library with so many features for modern development. JQuery is a fast and concise JavaScript library created by John Resig in 2006. It is a cross-platform JavaScript library designed to simplify client-side HTML scripting. Over 19 million websites are currently using jQuery! Companies like WordPress, Facebook, Google, IBM and many more rely on jQuery to provide a kind of web browsing experience.
https://jquery.com/
Bootstrap is not exclusively a CSS framework, but its most popular features are CSS-centric. These include a powerful grid, icons, buttons, map components, navigation bars, and more.
https://getbootstrap.com/
HTML (English "hyper text markup language" - hypertext markup language) is a special markup language that is used to create sites on the Internet.
Browsers understand html perfectly and can interpret it in an understandable way. In general, any page on the site is html-code, which the browser translates into a user-friendly form. By the way, the code of any page is available to everyone.
https://www.w3.org/html/
Welcome to the Q&A site for web developers. Here you can ask a question about the problem you are facing and get answers from other experts. We have created a user-friendly interface so that you can quickly and free of charge ask a question about a web programming problem. We also invite other experts to join our community and help other members who ask questions. In addition, you can use our search for questions with a solution.
Ask about the real problem you are facing. Describe in detail what you are doing and what you want to achieve.
Our goal is to create a strong community in which everyone will support each other. If you find a question and know the answer to it, help others with your knowledge.