开发者

How to get plain text response using AJAX using Dojo

开发者 https://www.devze.com 2023-04-10 06:07 出处:网络
I created a sample web service that return开发者_Go百科s a plain/text value (you can access it HERE (it\'s safe)). I just created something similar to those that I will use in my project. I tried usin

I created a sample web service that return开发者_Go百科s a plain/text value (you can access it HERE (it's safe)). I just created something similar to those that I will use in my project. I tried using Dojo's xhrGet method but it didn't work. I had read about The Same Origin Policy, so I tried dojo.io.script, but then it still didn't work. I'm a newbie in Dojo and Ajax so I really don't know what to do next. How will I do this in Dojo (or even in plain javascript)? Please help me. Thanks!


To retrieve via javascript get

    <script type="text/javascript">
            var xmlHttp = new XMLHttpRequest();
            xmlHttp.open( "GET", "http://jalbautista.xtreemhost.com/givename.php", false );
            xmlHttp.send( null );
            alert(xmlHttp.responseText);
    </script>

To retrieve via dojo (cross domain)

Use dojo.xd.js for cross domain build (or use the one provided by google see below) If you're going to use JSONP your script should spit out something like

doSomething("AUTO\\x-BautistaJ");

Script should look something like:

<script src="https://ajax.googleapis.com/ajax/libs/dojo/1.6.1/dojo/dojo.xd.js"></script>
    <script type="text/javascript">
    dojo.require("dojo.io.script");
    function doSomething(data){
            alert(data);
    }
    dojo.addOnLoad(function(){
    dojo.io.script.get( {url : "http://jalbautista.xtreemhost.com/givename.php",
                     callbackParamName : 'doSomething',
                     preventCache :true,
                     load : function(response, ioArgs) {
                                console.log("Response", response + ' ' + ioArgs);
                                return response;
                            },
                      error : function(response, ioArgs) {
                                console.log("Response error : ", response + ' '
                                              + ioArgs);
                               return response;
                            }
                     }
                   );
    });
    </script>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号