?
Solved

Best way to use javascript to pass one value to Ihttphandler

Posted on 2013-12-12
12
Medium Priority
?
286 Views
Last Modified: 2013-12-17
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:
      $.ajax({
         url: passUrl,
         type: 'POST',
         contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
         data: "ORDER_NO",
         success: function (result) {
            return false;
         }
      });

Open in new window


and this:

      $.getJSON(passUrl + "?OrderNumber=" + "ORDER_NO", function (data) {
      });

Open in new window


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.
0
Comment
Question by:Starr Duskk
[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
  • 7
  • 4
12 Comments
 
LVL 7

Expert Comment

by:cstsang
ID: 39715643
Just a wild guess:
$.ajax({
         url: passUrl,
         type: 'POST',
         contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
         data: "OrderNumber=ORDER_NO",
         success: function (result) {
            return false;
         }
      });

Open in new window

0
 
LVL 29

Accepted Solution

by:
sammySeltzer earned 2000 total points
ID: 39715645
Hi,

I am pretty new to ajax myself but from what I have learned so far, when you say another site's httpHandler, do you mean that your ajax is on one domain and the other site is another domain?

If so, ajax does not allow going across domain.

For instance, if your ajax is on http://www.domain1.com/something and the other site is http://www.domain2.com/something, then it won't work due to same origin policy.

I dealt with this situation recently and finally got it resolved.

If my assumption is wrong, then you can try something:


      $.ajax({
         url: passUrl,
         type: 'POST',
         contentType: 'application/x-www-form-urlencoded; charset=UTF-8',
         data: "ORDER_NO",
         success: function (result) {
         location = "pagefromtheOtherSite.aspx?ordernumber=" + ORDER_NO;
            return false;
         }
      });

Open in new window

0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717247
Cstsang,

On the retrieval end of the query I could retrieve it either way as a query string parameter:
      context.Response.ContentType = "text/plain"
      Dim param = context.Request.Params("OrderNumber")
 
or as an InputStream:
            Dim json As String = ""
            Using reader = New StreamReader(context.Request.InputStream)
               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.
0
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.

 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717262
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.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717321
I just tried jQuery.post and it fails too. Is that ajax also:

      var data = {
         "OrderNumber": "ORDER_NO"
      };

      jQuery.post(passUrl, data);
0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 39717431
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.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717441
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.AppendHeader("Access-Control-Allow-Methods", "POST")

I'll let you know how it goes.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717452
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.
0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 39717485
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.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39717504
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.AppendHeader("Access-Control-Allow-Methods", "POST")


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>

Open in new window


Sigh. Still going.
0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 39717516
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.
0
 
LVL 2

Author Comment

by:Starr Duskk
ID: 39725526
Thanks!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

770 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