jQuery AJAX - Unexpected token + parsererror

后端 未结 6 1980
被撕碎了的回忆
被撕碎了的回忆 2021-02-07 08:59

I wrote a script using jQuery and AJAX today, and I get some errors...

The script:

function changeAdmin(id) {
$(document).ready(function() {
    $(\'#ta         


        
6条回答
  •  说谎
    说谎 (楼主)
    2021-02-07 09:15

    Try code below, but if you receive an error like "Unexpected token <", you need to check your php file - "ajax_utf.php" and check what is returned in browser (Chrome) View->Developer->Developer Tools, Network tab -> XHR.

             $.ajax({
                    type: 'post',
                    url: postLink,
                    dataType: 'json',
                    data: postData,
    
                beforeSend: function (x) {
                    if (x && x.overrideMimeType) {
                        x.overrideMimeType('application/json;charset=UTF-8' );
                    }
                },
                success: function (result) {
                    //console.log(result);
                },
                error: function (xhr, ajaxOptions, thrownError) {
                    console.log(arguments);
                }
            });
    

提交回复
热议问题