JS Ajax calling PHP and getting ajax call data

前端 未结 3 1777
死守一世寂寞
死守一世寂寞 2021-01-24 22:19

I have a standard javascript ajax call where I\'m setting the data: to json data.

$.ajax({
    type: \"POST\",
    url: BaseUrl + \"User/Login\",    
    //url:          


        
3条回答
  •  悲&欢浪女
    2021-01-24 23:24

    I think problem with your code is in the line where you set data: '{....}'.
    It should be in json format in order to be passed properly (though it also could be in string format but you'll need to parse it on the server side)

    The code below should be working right:

    $.ajax({
        type: "post",
        url: BaseUrl + "User/Login",
        data: {"apiKey":"c7089786-7e3a-462c-a620-d85031f0c826","appIDGiven":"200","userName":"matt2","password":"pass"},
        success: function(data){
            console.log(data);
        },
        error: function(request){
            console.log(request);
        }
    });
    

    On the server side try: $_POST['apiKey'] $_POST['appIDGiven'] and so on.

提交回复
热议问题