0

I'm trying to retrieve specific data value by id from other page on my site by using query ajax.

by debugging on Chrome canary i have seen that I'm getting all the page data on dataAll ,and than its throwing me an error on line dataVal=$(dataAll).find('#counter').text();

also i don't want to use $("#div1").load("demo_test.txt"); method .

the error :

 Uncaught TypeError: Cannot read property 'parentElement' of null 
    RTE.Canvas.checkCurrentFocus

I'm using it on Content Editor web part for implement my script

<html>
  <head>
    <script type="text/javascript" src="~/SiteAssets/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
 var value;
 var dataVal;
 var dataAll;
$(document).ready
(function()
{
    value = $('div[id="cl"]').length;
    $("#cl").click
                    (function()
                    {
                        alert("HELLO WORLD! " + value);
                    }
                    );

    $.ajax(
            {url: '~/Forms/view1.aspx',
                success: function(dataAll) 
                {   
                    dataVal=$(dataAll).find('#counter').text(); 
                    $('#counte').html(dataVal);
                    alert('Done.');
                //  }
                }
                ,
                 error: function(){
                    alert('error!');
                }


            }
           );                       

}
);


</script>

  </head>
  <body>


<div id="counte">  <div>

<button id="cl">Click Me</button>   

  </body>
</html>

thank you very much

1 Answer 1

0

The error you are getting (I presume) is a side affect of the problem... YOu have a few miss-matched curly braces... I found this quickly just by copying your code and pasting it into a code editor... it highlighted the syntax issues...

Try this:

(function($){

    $(document).ready(function(){

        value = $('div[id="cl"]').length;

        $("#cl").click(function(){
            alert("HELLO WORLD! " + value);
        });

        $.ajax({
            url: '~/Forms/view1.aspx',  // are you sure this is working?
            success: function(dataAll){

                alert("AJAX SUCCESS: " + dataAll); // remove after you get it working

                dataVal=$(dataAll).find('#counter')

                // remove the IF below after you get it working
                if (!dataVal.length) { alert("#counter NOT FOUND in /Forms/view1.aspx!"); return; }

                dataVal = dtaaVal.text(); 

                $('#counte').html(dataVal);
                alert('Done.');

            },
            error: function(){
                alert('error!');
            }

        });

    });

})(jQuery);

This revised code is enclosed in a IIFE and scopes the $ variable to be local and pointed at jQuery... It also includes a few alert()'s to give you more hints at possible problems.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.