[SOLVED] Request ajax parse error

{
path: '/catalog/:id/',
componentUrl: './pages/catalog.html',  
async: function (routeTo, routeFrom, resolve, reject) {
    var router = this;
    var app = router.app;
    app.preloader.show();
    app.request({
        url: 'data/products.php',
        dataType: 'json',
        type: 'get',
        crossDomain: true,
        headers: { 'Accept': 'application/json; odata=verbose' },
        statusCode: {
            404: function(xhr) {
                console.log('page not found');
            }
        },
        complete: function() {
            console.log('complete');
        },
        success: function(response) {
            app.preloader.hide();
            resolve(
                    {
                        componentUrl: './pages/catalog.html',
                    },
                    {
                        context: {
                            products: response.d.results,
                        },
                    }
                );
        },
        error: function(xhr,status) {
            console.log(status);
        }
    });
   
  
}

},

Thisi is my code for routing, but the ajax call return me error parse in status… What’s wrong?

Means you have wrong jSON in response

This is my json:

{
  "results": [
    {
      "id": "1",
      "title": "title 1",
      "img": "img_1",
      "price": "2.00",
      "description": "desc"
    },
    {
      "id": "2",
      "title": "title_2",
      "img": "img_2",
      "price": "2.50",
      "description": "desc 2"
    }
  ]    

}

is it right?

It looks right here, but there could be something else in server response

//products:response.d.results
products:response.results

there is no ‘d’

Oh thanks, the parse error disapear!!

but still not running…

the ajax call has success but it does not load component… :sweat:

path:'/catalog/:id/',
//componentUrl:'./pages/catalog.html',  
async:function(routeTo,routeFrom,resolve,reject) {
2 Likes

Thank you very much… you have saved my day!!

Can you send the html file? I have such a problem too

Thanks

Same here. How did you fix your ajax parseerror. I have same problem.

$(’#login’).on(‘click’, function (e) {

				e.preventDefault();
				e.stopImmediatePropagation();
		
				var inptuser = $('#username').val();
				var inptpass = $('#password').val();
				var dataString="username="+ inptuser +"&password="+ inptpass;
				if (inptuser!="" && inptpass!=""){
				$.ajax({
						type: "GET",
						url: "https://wexpushy.xyz/project/auth.php",
						data: dataString,
						dataType: "json",
						timeout: 10000,
						crossDomain: true,
						cache: false,
						success: function(data) 
						{  
							$.getJSON("https://wexpushy.xyz/project/auth.php?"+dataString, function(result) {
								console.log(result);
								$.each(result, function(i, field) {
								var username     =   field.username;
								var password    =   field.password;
								alert('Login Success');
								window.location.href="home.html?username="+username;
								});
							});
						},
						error: function(jqXHR, exception)
						{
							console.log(jqXHR);

							var msg = "";

					if (jqXHR.status === 0){

                   		 	msg = 'Not connect.\n Verify Network.';

						 } else if (jqXHR.status == 404) {
  						 	msg = 'Requested page not found. [404]';
							}
						else if (jqXHR.status == 500) {
   							msg = 'Internal Server Error [500].';

   						} else if (exception === 'parsererror'){

   							msg = 'Invalid Username and Password.';

   						} else if (exception === 'timeout') {
   							msg = 'Time out error.';

						} else if (exception === 'abort') {
							msg = 'Ajax request aborted.';

						} else {
    						msg = 'Uncaught Error.\n';
						 }

                    	 alert(msg);

							// alert('Invalid Username or Password !');
							// window.location.href = "#";
						}
						   });

						}

					else{
        					alert('Please fill all the field !');
   						}

							localStorage.setItem('username',inptuser);
						  });

I wanted to execute the (jqXHR.status == 404) but (exception === ‘parsererror’) would appear.

Anyone can help me fix thanks!