简体   繁体   中英

Parse error in response of AJAX call

I am new to javascript and jquery, in my code I'm initiating a AJAX call and I get the following response.

在此处输入图片说明

I'm trying to implement an autocomplete functionality. I am using below code to do AJAX call.

$( "#city" ).autocomplete({
      source: function( request, response ) {
        jQuery.ajax({
          url: "the url",
          data: {SearchTerm: request.term}
          success: function (data) {
               console.log("the data is" +data); 
               response(data);
            }
        }).fail(function (jqXHR, textStatus, error) {
             console.log("failure1" + textStatus);
             console.log("failure2" + jqXHR.status);
    });
      },
      minLength: 3,
      select: function( event, ui ) {
        console.log( ui.item ?
          "Selected: " + ui.item.label :
          "Nothing selected, input was " + this.value);
      },
      open: function() {
        $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
      },
      close: function() {
        $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
      }
    });
  });

Even though I see 200 response from the server and the response in JSON format, success method doesn't get called and fail get called. Since I'm getting JSON response with 200 status, doesn't success method should get called?

Try this, may be this will help you :

Option 1 :

May be you accidently turning On Magic Quotes in PHP
But this function is already deprecated in PHP 5.3.0.
And REMOVED as of PHP 5.4.0. as mentioned in here

  • Go to your php.ini file
  • Search this keyword : magic_quotes_gpc
  • Set it to OFF : magic_quotes_gpc = Off

Option 2 :

Do it on your code like this :

 if (get_magic_quotes_gpc()) { $returnedValue = stripslashes($yourReturnedValue); } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM