Solved

AJAX error in request

Posted on 2014-03-26
5
1,310 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now