issues taking PHP html string, jsonencoding and passing back as part of an AJAX call
I am having an issue that is built upon a previous question that was very kindly answered.
I have an html string that makes up a php function that is being called by an AJAX function.
To start, I am just logging the data coming back to the console but I am getting nothing. No errors, no data, nothing in the log. The console doesnt even display the line where the console.log is.
I do know the AJAX is running since I tested it by putting an alert at the start of the function before the jQuery.ajax({... It worked.
But when I moved the alter after the success: function(data){ - no alert making me think no data is being received.
I am unsure if the issue is on the PHP side or AJAX side.
The code - AJAX
function ajaxfunction(){
jQuery.ajax({
data: {action: 'myphpfunction' },
type: 'post',
url: my_ajax.ajax_url,
dataType: 'JSON',
success: function(data){
console.log(data)
});
}
the PHP
function myphpfunction() {
$html_string = '';
foreach($a as $value){
$html_string .= '<div class="myclass">{$value-> Name}</div><div class="myclass">{$value-> email}</div>';
$cid[] = $value->id_In_Restaurant;
};
echo json_encode(array('html' => $html_string, 'cid' => $cid));
};
Anyone able to help me on where I am going wrong?
from Recent Questions - Stack Overflow https://ift.tt/3a2w9RJ
https://ift.tt/eA8V8J
Comments
Post a Comment