Solved

AJAX error in request

Posted on 2014-03-26
5
1,557 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 36

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Chart.js, used properly, can visually add a difference to your charting applications. It engages your visitors and allows them to interact with data they otherwise wouldn't be able to without expensive and complicated systems. For this…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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)
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…

690 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