How to call external .js file with ajax?

Discussion in 'JavaScript' started by Jen-, Sep 28, 2006.

  1. #1
    Hello, I was told external .js files could be called with ajax. Anyone know how?

    Thank you very much!! Jen
     
    Jen-, Sep 28, 2006 IP
  2. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi,

    All JS files included from a document are interpreted in the same environment so if the script containing your function is included then you can call the function directly.

    AJAX (XMLHttpRequest) is a technique used to call server-side scripts from the client scripting environment. Look up RPC for more information on that.

    Regards
    - P
     
    penagate, Sep 30, 2006 IP
  3. AlilG

    AlilG Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    look like wehn you want call a TEXT or HTML file, but with use of eval method!
    now you receive a text file result in ajax by this: HTTPRequest.ReponseText right?

    and now if you called a .js file, to run all functions and javascripts codes at this file you should use of this: "eval(HTTPRequest.ResponseText)"
    thats alone
     
    AlilG, Sep 30, 2006 IP
  4. bandito

    bandito Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Hi Jen,

    what is it you are trying to do?

    If you are trying to access data served from a different domain to the one that you are serving the page from then you should do some research about the script tag hack. Otherwise you will be dealing with cross domain security issues with your browser.

    Let me know if you would like more info as i've done quite a bit of research into this issue for a current project development.
     
    bandito, Sep 30, 2006 IP
  5. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hey Bandito thats cool, sorry I was tied up for a bit. I need to know if I can call a js external script without putting my the external address into my source code. I am trying to protect a script it took me too long to write.
    Please let me know if your research taught you if this is possible. Thanks Jen
     
    Jen-, Oct 15, 2006 IP
  6. Morishani

    Morishani Peon

    Messages:
    239
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Well, if someone will try to take your script, he will . nobody can defend you script. even not ajax.
     
    Morishani, Oct 16, 2006 IP
  7. Jen-

    Jen- Peon

    Messages:
    151
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Some of us can try because we spend months and years writing complicated scripts. Please let some of us try if we need to. You don't have to agree with it. Thanks.
     
    Jen-, Oct 16, 2006 IP
  8. jsfan

    jsfan Peon

    Messages:
    5
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #8
    There is no real way to hide your script. You may try something like this but it is wired. It only makes it difficult to get your script. [I THINK]


    * Encrypt the script at server side before rendering
    * Using AJAX get the key used for encryption from server
    * Get the encrypted script from server
    * Use some javascript crypto functions [dojotoolkit.org] to decrypt the
    javascriptscript and use eval() as explained by earlier poster.



    But that still wont prevent someone from copying your script. You may want to generate different keys everytime ..but still it does not serve your purpose :D :D :D :eek:

    http://ashishware.com
     
    jsfan, Oct 16, 2006 IP
  9. penagate

    penagate Guest

    Messages:
    277
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    0
    #9
    There is simply no way to hide client side code since if there was it could not be parsed by the user agent. Same with HTML, CSS, etc.

    If you have a copyright notice in your script header, you are fully within your rights to pursue legal action if someone rips a decent-sized chunk out of it for their own gain.
     
    penagate, Oct 16, 2006 IP
  10. intoex

    intoex Peon

    Messages:
    414
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You can obfuscate your code, look for example on google's :)
    btw, if you haven't any unique idea, nobody will crack your code, because it will be much easier to write similar themselves
     
    intoex, Oct 19, 2006 IP