Click here to Skip to main content
15,891,662 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I working on WebMethod using ajax call. Below is my working code and not working code. How to declare reWrite rule inside ajax call url ?

Working Code ( This works perfectly ):
Page Name : WebForm2.aspx
URL name : http://blalbla.com/WebForm2.aspx
$(document).ready(function () {
var obj;
$.ajax({
type: "POST",
url: "WebForm2.aspx/GetState",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
--------

Not Working Code :
Page Name : WebForm2.aspx
URL Name : http://blalbla.com/one/two

$(document).ready(function () {
var obj;
$.ajax({
type: "POST",
url: "/one/two/GetState",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
Posted
Comments
Kornfeld Eliyahu Peter 24-Jan-16 9:44am    
Rewrite rules are declared on the server not in your code...
Krishna Varadharajan 25-Jan-16 3:09am    
I agree with you, than what mistake I am doing, same url is working if I create in empty solution. But this is not working in the project solution. I tried by giving direct URL like below, but it is not calling the webmethod GetState.
url : http://stage.xxyy.com/WebForm2.aspx/GetState
Sergey Alexandrovich Kryukov 24-Jan-16 19:43pm    
There is no such concept as "call a rule". You just need to use correct URI in your Ajax call. Rewrite rule have nothing to do with Ajax and any of your client code at all.
—SA
Krishna Varadharajan 25-Jan-16 3:04am    
ok I got you point, than why I am unable to call if I give the URL as url : WebForm2.aspx/GetState

Sinisa Hajnal 25-Jan-16 2:42am    
You need to use real URL in your javascript. You can hide it in global variable, setting it from server or in one of the files you link if you don't want simple view page source to show real path. But somewhere in the client code you have to have correct address.

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