0

For an AJAX call I try to get the url from a variable

jQuery(document).ready(function($) {
var url = 'test';
$.ajax({
    'url': url,
    'data': ({todo: "food-page_catfetch"}),
    'success': function(data) {
        $('.catspinner__food_page').fadeOut("fast", function(){
            $('#food_result__cats').html(data);
        });
    }
});
});

If I look in the inspector I see this

jQuery(document).ready(function($) {
var url = 'test';
$.ajax({
    'url': url, 
    'data': ({todo: "food-page_catfetch"}),
    'success': function(data) {
        $('.catspinner__food_page').fadeOut("fast", function(){
            $('#food_result__cats').html(data);
        });
    }
});
});

And I want this

'url': test, 

I tried different ways but I cant fixed this who can help me?

2
  • what you want and what you have are equivalent, url is a variable containing the string 'test'. Whatever the problem is that you're trying to solve, this is a red herring, it already does what you are trying to make it do, it is not the source of your problem. But even if it was ( which it isn't ) you can just edit url to test in the code. Perhaps you need to explain things differently? If this question is pure javascript then you should ask it on stackoverflow
    – Tom J Nowell
    Jan 6 '20 at 0:18
  • you may be thinking in php Jan 6 '20 at 1:04
0

try with Axios instead jQuery and check the response, example

let form_data = new FormData;
form_data.append('action', 'myAction');
form_data.append('first_name', 'my first name');

axios.post(myVars.ajax_url, form_data).then(function(response){
  console.log('response', response.data);
}).cath(console.log)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.