如何用ajax和codeigniter解决400(错误请求)错误

I am getting a 400 (Bad Request) error with ajax and codeigniter

this is my ajax call

$.ajax({
            type: "POST",
            url: '<?php echo base_url(); ?>query/sensor/'+ test + / + past  + / + id + / + port + / + device,

            success: function(res) {
            if (res)
            {

                console.log("res"+res);
                    }
            }
            });


      }

is it a proper ajax url?

  • First Make sure you get variables values test, past ....
  • You can change url: 'query/sensor/'+ test + / + past + / + id + / + port + / + device,

    With this url:

url: 'query/sensor/'+ test +'/' + past + '/' + id + '/' + port + '/' + device,

regards :)

$.post(
"your_url", 
{
  value1: value1,
  value2: value2,
  value3: value3,

}, 
function(result){

  alert(result);
});

Use this post method