Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
The simple question: How do I run a remote aspx webservice dynamically from Javascript?

Background Info:
There is a 3rd party remote aspx webservice that I normally run with no problems from a Wordpress webpage by simply putting it in like this:

<script type=’’ src=’http://boo.foo.com/Remote-Frame.aspx'></script>


FYI… this aspx actually inserts an iframe into my page at this location within the page which provides the user with a MLS Search Tool.

This works just great, but this script, of course, loads/runs at page load time and I don’t want that anymore.

What I want to do:
I want to "run it" when, for example, a user clicks on a button.

Here is a snippet of what I have thus far, but the webservice doesn't actually run.

XML
<div id=’homesearch’></div>
<script type='text/javascript'>
  var ss = document.createElement('script');
  ss.type = '';
  ss.async = false;
  ss.src = ’http://boo.foo.com/Remote-Frame.aspx';
  var dd = document.getElementById('homesearch');
  dd.parentNode.insertBefore(ss, dd);

  But now how do I tell it to "run"?
</script>

The solution?
What am I missing or maybe there is a simpler solution. And keep in mind that the solution must work in all major browsers. Thank you in advance.
Posted
Updated 19-Jul-13 17:28pm
v2

That script should run when the page loads. So if you dont see your iframe theres something wrong with that javascript. If you want it to run on the click of a button wrap that code into a function and call that fucntion on a button click.
C#
<div id="’homesearch’"></div>
<script type='text/javascript'>
function showSearch(){
  var ss = document.createElement('script');
  ss.type = '';
  ss.async = false;
  ss.src = ’http://boo.foo.com/Remote-Frame.aspx';
  var dd = document.getElementById('homesearch');
  dd.parentNode.insertBefore(ss, dd);
 }
</script>

<input .....="" onclick="showSearch();"></input>
 
Share this answer
 
Comments
Brian Adamski 19-Jul-13 23:11pm    
Like I said, what I showed was just a code snippet. Yes I realize that the way I show my code snippet it would load a runtime. I should have showed it like you did. Nevertheless, the Remote-Frame.aspx is not called in either case.
Yuriy Loginov 19-Jul-13 23:16pm    
You should trying creating the iframe manually. <iframe src=" your url" ......
Brian Adamski 19-Jul-13 23:32pm    
Yup I tried that! I created the iframe exactly as the webservice does and 99% of the webservice works just fine, but for whatever reason a very important 1% does not. And forgive me earlier terminology as basically I'm trying to call a aspx webservice from Javascript.
Yuriy Loginov 20-Jul-13 0:14am    
Feel free to mark the question answered
Brian Adamski 20-Jul-13 1:02am    
I would love to mark the question as answered, but unfortunately my question is still not answered as creating the iframe doesn't provide a 100% workable solution.
It's hard even to understand what do you confuse, maybe the notion of the "script" itself. ASP.NET is executed on the server side, JavaScipt — on the client side. There is no such thing as "execute" ASP.NET script. You simply send HTTP request using URL and perhaps some POST (or other request method: GET, HEAD, PUT, etc.) data. The request is received by the HTTP server and possibly passed through ASP.NET script, which actually generate the whole HTTP response which is delivered to the client side.

In your JavaScript button handler you can 1) simply redirect to the ASP.NET page, 2) send Ajax request with the URL of this page.

—SA
 
Share this answer
 

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