Starr Duskk
asked on
Best way to use javascript to pass one value to Ihttphandler
I want to create a javascript to use on another site that will pass one single ID field to a second site's Ihttphandler.
I have tried this:
and this:
But both fail when using Internet Explorer. Any other suggestions I can try? I'm asking in this forum because I'd like to get the perspective of an ASP.NET developer, not a javascript developer.
thanks.
I have tried this:
$.ajax({
url: passUrl,
type: 'POST',
contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
data: "ORDER_NO",
success: function (result) {
return false;
}
});
and this:
$.getJSON(passUrl + "?OrderNumber=" + "ORDER_NO", function (data) {
});
But both fail when using Internet Explorer. Any other suggestions I can try? I'm asking in this forum because I'd like to get the perspective of an ASP.NET developer, not a javascript developer.
thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Cstsang,
On the retrieval end of the query I could retrieve it either way as a query string parameter:
context.Response.ContentTy pe = "text/plain"
Dim param = context.Request.Params("Or derNumber" )
or as an InputStream:
Dim json As String = ""
Using reader = New StreamReader(context.Reque st.InputSt ream)
json = reader.ReadToEnd()
End Using
So both your way and mine have been tried and work in Chrome, but not in IE since last week.
On the retrieval end of the query I could retrieve it either way as a query string parameter:
context.Response.ContentTy
Dim param = context.Request.Params("Or
or as an InputStream:
Dim json As String = ""
Using reader = New StreamReader(context.Reque
json = reader.ReadToEnd()
End Using
So both your way and mine have been tried and work in Chrome, but not in IE since last week.
ASKER
sammySeltzer,
>>ajax does not allow going across domain.
This all worked last week and had been working for months until MS did the latest update, so I don't know what happened between now and then. Unless the ecommerce site made changes and broke it, which they are saying they did not.
Plus, this method works great with Chrome and Firefox, just fails on version IE8, IE10, and IE11. (I didn't try IE9.) All which worked last week.
>>I dealt with this situation recently and finally got it resolved.
How did you resolve it?
thanks.
>>ajax does not allow going across domain.
This all worked last week and had been working for months until MS did the latest update, so I don't know what happened between now and then. Unless the ecommerce site made changes and broke it, which they are saying they did not.
Plus, this method works great with Chrome and Firefox, just fails on version IE8, IE10, and IE11. (I didn't try IE9.) All which worked last week.
>>I dealt with this situation recently and finally got it resolved.
How did you resolve it?
thanks.
ASKER
I just tried jQuery.post and it fails too. Is that ajax also:
var data = {
"OrderNumber": "ORDER_NO"
};
jQuery.post(passUrl, data);
var data = {
"OrderNumber": "ORDER_NO"
};
jQuery.post(passUrl, data);
Bob,
If this used to work for you, then it seems like my situation is different from yours.
In my case, which was clearly a case of cross-domain scripting issue, I had to write a proxy Server (asp) to point to the location the ajax was trying to reach and then my ajax points to the proxy to get data and everybody was happy.
But as I stated, if yours used to work before, cross-domain scripting is not your issue *UNLESS* the old server has cross-domain policy in place that allows for cross-domain scripting but has not been ported to the new one.
If this used to work for you, then it seems like my situation is different from yours.
In my case, which was clearly a case of cross-domain scripting issue, I had to write a proxy Server (asp) to point to the location the ajax was trying to reach and then my ajax points to the proxy to get data and everybody was happy.
But as I stated, if yours used to work before, cross-domain scripting is not your issue *UNLESS* the old server has cross-domain policy in place that allows for cross-domain scripting but has not been ported to the new one.
ASKER
I used the MS debugger in IE to see what I could see. I got error:
xmlhttprequest required cross origin resource sharing (cors)
I am going to try adding this to my iHttphandler:
context.Response.AppendHea der("Acces s-Control- Allow-Meth ods", "POST")
I'll let you know how it goes.
xmlhttprequest required cross origin resource sharing (cors)
I am going to try adding this to my iHttphandler:
context.Response.AppendHea
I'll let you know how it goes.
ASKER
Sammy,
Yeah, I don't know what changed from last week to this week. Something on some server. We host through Rackspace, so I don't know if they turned something off.
I'm going to try the above thing I said and let everyone know.
thanks.
Yeah, I don't know what changed from last week to this week. Something on some server. We host through Rackspace, so I don't know if they turned something off.
I'm going to try the above thing I said and let everyone know.
thanks.
Yep, so there is same origin /same domain restriction I talked about initially.
I would start by trying to determine, as I indicated, if there is a cross-origin or cross-domain policy in place in old server that should also be in place in the new server.
Some people work around this by turning it off on browser but then this can only be done on firefox as I understand it.
I would start by trying to determine, as I indicated, if there is a cross-origin or cross-domain policy in place in old server that should also be in place in the new server.
Some people work around this by turning it off on browser but then this can only be done on firefox as I understand it.
ASKER
I don't recall saying anything about old or new server. There is and always has been only the one server. It just stopped working last week.
Adding this still fails:
context.Response.AppendHea der("Acces s-Control- Allow-Meth ods", "POST")
I also did check my web.config and found that I already have this.
Sigh. Still going.
Adding this still fails:
context.Response.AppendHea
I also did check my web.config and found that I already have this.
<!--allows cross domain cross site script postings from ecommerce
http://enable-cors.org/server_iis7.html
-->
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Origin, X-Requested-With, Content-Type, Accept" />
</customHeaders>
</httpProtocol>
Sigh. Still going.
Sorry, I mistook this statement:
on another site that
to mean another server but the concept is still same though.
http://domain1/something
is different from http://domain2/something and result to good old cross-scripting error but there are more experienced experts on this than me.
I am just speaking of my own experience.
on another site that
to mean another server but the concept is still same though.
http://domain1/something
is different from http://domain2/something and result to good old cross-scripting error but there are more experienced experts on this than me.
I am just speaking of my own experience.
ASKER
Thanks!
Open in new window