Solved

AJAX error in request

Posted on 2014-03-26
5
1,367 Views
Last Modified: 2014-05-27
I am calling WCF REST using Jquery, that works fine in IE,But is not working in any other browser like Mozilla,Chrome . while calling the WCF REST from like Mozilla Firefox I am getting the error :

AJAX error in request: {
  "readyState": 0,
  "responseText": "",
  "status": 0,
  "statusText": "error"
}

Open in new window


I am attaching the code:
<script type="text/javascript">
    $(document).ready(function(){	
	
	// Declare all the variables.
	var exampleValues = {};
	var Activity = 'SELL';
	var Exchange = 'NSE';
	var param1 = 'ALL';
	var param2 = ' ';
	var param3 = 'ALL';
	var param4 = 'xxxx';
	var str = "http://santu-379/WCFClient/WCFClient.Service1.svc/GetFirst_PDH_PDL/" + Activity + "/" + Exchange + "/" + param1 + "/" + param2  + "/" + param3 + "/" + param4;
//alert(str);
	jQuery.support.cors = true;
	$.ajax({
		 url: str,
		 type: "GET",
		 async: "false",
		 data: '{}',
		 crossDomain: true,
		 contentType: "application/json; charset=utf-8",
		 dataType: "json",
		 
		 //processData: true,
		 complete: function() {
		   // alert('done');
		    },
		 success: function(data)
		  {
		     //alert(data);
		      var obj = $.parseJSON(data);		       
		      $('#templateStructure').template('myTemplate');
		      // bind the data to the template and append to the table
		      $.tmpl('myTemplate', obj).appendTo('#templateTable');
		      //$("#flickrTemplate").tmpl((obj)).appendTo("#placeholder");
		  },
		 error: function (err) {
		       alert("AJAX error in request: " + JSON.stringify(err, null, 2));
	       } 
	});
	
	
	});
	
    
    </script>

Open in new window

0
Comment
Question by:dynamicweb09
5 Comments
 
LVL 5

Expert Comment

by:jayakrishnabh
ID: 39958224
Please try this...
Limit url string to till Methodname and pass the parameters through JSON data.
Example :
var str = "http://santu-379/WCFClient/WCFClient.Service1.svc/GetFirst_PDH_PDL/";
//(if GetFirst_PDH_PDL is the method name that has four input parameters Param1Name, //Param2Name, Param3Name, Param4Name)
var jsonData = { Param1Name : param1, Param2Name : param2, Param3Name : param3, Param4Name : param4}

$.ajax({
             url: str,
             type: "GET",
             async: "false",
             data: jsonData ,
             crossDomain: true,
             contentType: "application/json; charset=utf-8",
             dataType: "json",
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39958493
Use encodeURIComponent :
	var Activity = 'SELL';
	var Exchange = 'NSE';
	var param1 = 'ALL';
	var param2 = encodeURIComponent(' '); // or '+' or '%20'
	var param3 = 'ALL';
	var param4 = encodeURIComponent('xxxx'); // I suppose it's not really xxxx

Open in new window

0
 
LVL 35

Expert Comment

by:Miguel Oz
ID: 39970962
Please post the WCF operation declaration of GetFirst_PDH_PDL.
Need to check how the URI is defined as well as the method parameters.
0
 
LVL 1

Author Closing Comment

by:dynamicweb09
ID: 40092364
ok
0
 
LVL 82

Expert Comment

by:leakim971
ID: 40092755
why a "C" grade ?
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question