Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1912
  • Last Modified:

AJAX error in request

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
dynamicweb09
Asked:
dynamicweb09
1 Solution
 
jayakrishnabhCommented:
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
 
leakim971PluritechnicianCommented:
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
 
Miguel OzSoftware EngineerCommented:
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
 
dynamicweb09Author Commented:
ok
0
 
leakim971PluritechnicianCommented:
why a "C" grade ?
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now