admin管理员组文章数量:1130349
I have an issue with Javascript that I created for my custom widget.
Here is the code:
var wrapper = $('#wrapper'), container;
$.ajax({
method: "POST",
url: "",
contentType: "application/json",
headers: {
Authorization: "bearer ******"
},
data: JSON.stringify({
query: "query { allProducts { id title } }"
})
}).done(function(data) {
for( var key in data ) {
for (var i = 0; i<data[key].allProducts.length; i++)
{
console.log(data[key].allProducts[i]);
container = $('<div id="data" class="container"></div>');
wrapper.appendTo(container);
container.appendTo('<input type=checkbox name="id" value=' + data[key].allProducts[i].id + '>' + data[key].allProducts[i].title );
}
}
});
Here is how I'm calling the Jquery in my functions.php file for the template:
function jquery_import() {
wp_deregister_script('jquery');
wp_register_script('jquery',.3.1/jquery.min.js', array(), '3.3.1', true);
wp_enqueue_script('jquery');
}
add_action( 'wp_enqueue_scripts', 'jquery_import' );
Here is how I'm calling my custom javascript file:
function custom_wp_enqueue_scripts() {
wp_register_script( 'custom', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), NULL, false );
wp_enqueue_script( 'custom' );
}
add_action('wp_enqueue_scripts', 'custom_wp_enqueue_scripts');
Finally, in my widget here is the following div statement:
<div id="wrapper"> </div>
Based on my javascript, data is coming in, however, the information is not displayed in my widget. Why it isn't showing in my widget?
Thank you, Kevin Davis
I have an issue with Javascript that I created for my custom widget.
Here is the code:
var wrapper = $('#wrapper'), container;
$.ajax({
method: "POST",
url: "https://api.graphcms/simple/v1/SampleAPI",
contentType: "application/json",
headers: {
Authorization: "bearer ******"
},
data: JSON.stringify({
query: "query { allProducts { id title } }"
})
}).done(function(data) {
for( var key in data ) {
for (var i = 0; i<data[key].allProducts.length; i++)
{
console.log(data[key].allProducts[i]);
container = $('<div id="data" class="container"></div>');
wrapper.appendTo(container);
container.appendTo('<input type=checkbox name="id" value=' + data[key].allProducts[i].id + '>' + data[key].allProducts[i].title );
}
}
});
Here is how I'm calling the Jquery in my functions.php file for the template:
function jquery_import() {
wp_deregister_script('jquery');
wp_register_script('jquery',https://ajax.googleapis/ajax/libs/3.3.1/jquery.min.js', array(), '3.3.1', true);
wp_enqueue_script('jquery');
}
add_action( 'wp_enqueue_scripts', 'jquery_import' );
Here is how I'm calling my custom javascript file:
function custom_wp_enqueue_scripts() {
wp_register_script( 'custom', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), NULL, false );
wp_enqueue_script( 'custom' );
}
add_action('wp_enqueue_scripts', 'custom_wp_enqueue_scripts');
Finally, in my widget here is the following div statement:
<div id="wrapper"> </div>
Based on my javascript, data is coming in, however, the information is not displayed in my widget. Why it isn't showing in my widget?
Thank you, Kevin Davis
Share Improve this question asked Jan 4, 2019 at 16:33 Kevin DavisKevin Davis 11 Answer
Reset to default 0Try changing...
var wrapper = $('#wrapper'), container;
To just...
var wrapper = $('#wrapper');
then add var in front of container
var container = $('<div id="data" class="container"></div>');
I have an issue with Javascript that I created for my custom widget.
Here is the code:
var wrapper = $('#wrapper'), container;
$.ajax({
method: "POST",
url: "",
contentType: "application/json",
headers: {
Authorization: "bearer ******"
},
data: JSON.stringify({
query: "query { allProducts { id title } }"
})
}).done(function(data) {
for( var key in data ) {
for (var i = 0; i<data[key].allProducts.length; i++)
{
console.log(data[key].allProducts[i]);
container = $('<div id="data" class="container"></div>');
wrapper.appendTo(container);
container.appendTo('<input type=checkbox name="id" value=' + data[key].allProducts[i].id + '>' + data[key].allProducts[i].title );
}
}
});
Here is how I'm calling the Jquery in my functions.php file for the template:
function jquery_import() {
wp_deregister_script('jquery');
wp_register_script('jquery',.3.1/jquery.min.js', array(), '3.3.1', true);
wp_enqueue_script('jquery');
}
add_action( 'wp_enqueue_scripts', 'jquery_import' );
Here is how I'm calling my custom javascript file:
function custom_wp_enqueue_scripts() {
wp_register_script( 'custom', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), NULL, false );
wp_enqueue_script( 'custom' );
}
add_action('wp_enqueue_scripts', 'custom_wp_enqueue_scripts');
Finally, in my widget here is the following div statement:
<div id="wrapper"> </div>
Based on my javascript, data is coming in, however, the information is not displayed in my widget. Why it isn't showing in my widget?
Thank you, Kevin Davis
I have an issue with Javascript that I created for my custom widget.
Here is the code:
var wrapper = $('#wrapper'), container;
$.ajax({
method: "POST",
url: "https://api.graphcms/simple/v1/SampleAPI",
contentType: "application/json",
headers: {
Authorization: "bearer ******"
},
data: JSON.stringify({
query: "query { allProducts { id title } }"
})
}).done(function(data) {
for( var key in data ) {
for (var i = 0; i<data[key].allProducts.length; i++)
{
console.log(data[key].allProducts[i]);
container = $('<div id="data" class="container"></div>');
wrapper.appendTo(container);
container.appendTo('<input type=checkbox name="id" value=' + data[key].allProducts[i].id + '>' + data[key].allProducts[i].title );
}
}
});
Here is how I'm calling the Jquery in my functions.php file for the template:
function jquery_import() {
wp_deregister_script('jquery');
wp_register_script('jquery',https://ajax.googleapis/ajax/libs/3.3.1/jquery.min.js', array(), '3.3.1', true);
wp_enqueue_script('jquery');
}
add_action( 'wp_enqueue_scripts', 'jquery_import' );
Here is how I'm calling my custom javascript file:
function custom_wp_enqueue_scripts() {
wp_register_script( 'custom', get_template_directory_uri() . '/assets/js/custom.js', array( 'jquery' ), NULL, false );
wp_enqueue_script( 'custom' );
}
add_action('wp_enqueue_scripts', 'custom_wp_enqueue_scripts');
Finally, in my widget here is the following div statement:
<div id="wrapper"> </div>
Based on my javascript, data is coming in, however, the information is not displayed in my widget. Why it isn't showing in my widget?
Thank you, Kevin Davis
Share Improve this question asked Jan 4, 2019 at 16:33 Kevin DavisKevin Davis 11 Answer
Reset to default 0Try changing...
var wrapper = $('#wrapper'), container;
To just...
var wrapper = $('#wrapper');
then add var in front of container
var container = $('<div id="data" class="container"></div>');
本文标签: ajaxJavascript output now showing in custom widget
版权声明:本文标题:ajax - Javascript output now showing in custom widget 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749044375a2307634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论