Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
JavaScript
$("#year").change(function()
        {  
       	 var id = $(this).val();
        	$.ajax({
        	url:'Servlet',
        	type:"get",
        	dataType: "json",
        	async: false,
        	 cache: false,
        processData: false,  
        	data: id,
        	sucess: function(result) {
        
        	alert(result);
        	
        	
        	
        }, 	
        	error: function(req, err)
        	{ 
        	console.log('my message' + err); 
        	}
        	});
        	
        	return false;
        });



In the above code jQuery ajax call keeps on giving error and not success.
Please have a look and let me know if you find any issue in this code.

Thanks in advance.
Posted
Updated 27-Oct-14 23:08pm
v2
Comments
Laiju k 28-Oct-14 4:48am    
have you used debugger
Navi.jsp 28-Oct-14 5:17am    
yes. now my param have the value , but my response showing the whole jsp I am not sure why
Navi.jsp 28-Oct-14 5:18am    
I got a requestdispatcher at my doGet

1 solution

Basically the parameters to be sent must be in JSON format but you are sending the parameter direct value here.

What i think the format should be here is :-

JavaScript
var id = $(this).val();

* * * * * * * * * 

data: "{Id:" + id + "}"

* * * * * * * * * 


Also URL here you sent as 'Servlet', this should be the operation URL not sure what do you mean by 'Servlet' here.

Please change this as mentioned here and check once if it works for you.

Here is a sample ajax call i have pasted below for your help :-
Ex :
JavaScript
$.ajax({
        type: "GET",
        url: "../WebMethods/WebService.asmx/GetData",
        data: "{regId:" + regId + "}",
        dataType: "json",
        async: false,
        success: function (response) {
            return true;
        }
    });


Again you can also use the console window to get the error information like :-

Open the page press F12, developers tool will open
Now click on 'Console' tab and do the operation you want.
Any javascript error can be caught here.
 
Share this answer
 
Comments
Navi.jsp 28-Oct-14 5:37am    
now my console keep printing false undefined, servlet is my j2ee web form
SRS(The Coder) 28-Oct-14 6:07am    
This means your code using some variable which is not defined yet.
The URL should keep the URl of the operation. It should be Page or Web static Methods only. Please go through the ajax request making full tutorial once here :-

Reference :-
http://www.aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx
Navi.jsp 28-Oct-14 8:09am    
how about parseerror?
SRS(The Coder) 28-Oct-14 8:36am    
it is due to not able to parse the data passed by you as parameter, it is expecting JSON formated and you are passing the direct value directly.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900