jQuery AJAX/POST not sending data to PHP

前端 未结 7 1364
春和景丽
春和景丽 2020-12-29 03:54

So I have this problem for a while now, and I know there are countless questions on this topic, believe me I tried every solution possible but still does not work.

T

相关标签:
7条回答
  • 2020-12-29 04:53

    Try to edit your code and use:

    $.ajax({url: 'ajax/add-user.php',
    type: 'POST',
    data: {name: 'John'},
    dataType: 'html',
    success: function(data){
    alert("success");
    console.log(data);
    },error: function (xhr, ajaxOptions, thrownError) {alert("ERROR:" + xhr.responseText+" - "+thrownError);}
    });
    

    (so you will receive an error & success alert, ensure is html what you receive.those extra parameters will help you to fine-tune your ajax calls. Later play with async true/false)

    also, run your program ajax/add-user.php in a new window (type the url) and see what it echoes.Edit the program and force to echo you something "i.e. legendary hello world" and see if your ajax receive the message.

    Good luck.

    0 讨论(0)
提交回复
热议问题