Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

So I am trying to learn these both as I read nuthin but great things all over the place about them.

So this is what I have from example on codeplex:

<script type="text/javascript" src="http://espdev:44485/Style%20Library/jquery/jquery-1.7.2.min.js"></script>
<script type ="text/javascript" src="http://espdev:44485/Style%20Library/jquery/jquery.SPServices-0.7.1a.min.js"></script>
<script type="text/javascript">

$(document).ready(function() {
        var subject = "Hi Subject!";
        var message = "Hi Message!";
        CreateNewItem(subject, message);        
});

function CreateNewItem(subject, message) {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "FirstList",
        valuepairs: [["Title", subject], ["Message", message]],
        completefunc: function(xData, Status) {
          alert("completed");
        }
    });}

</script>

So this doesn't seem to work as I load the page, and as I understand it should. Is there something I am missing? I do have the scriptlinks and have this in a text file in a document library and have a CEWP referencing the file.

Again, I am learning so if there is something of context I missing here I certainly appreicate the help! Thanks!

EDIT: Added the script references to the example; again I also tried the network delivery links in place of the above and got the same results?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I tested your code. It is working. Are the column names right: Title and Message? Before you test this code with a custom list, try a standard list, like Posts (in Office 365), or Announcements:

function CreateNewItem(subject, message) {
    $().SPServices({
        operation: "UpdateListItems",
        async: false,
        batchCmd: "New",
        listName: "Posts",
        valuepairs: [["Title", subject], ["Body", message]],
        completefunc: function(xData, Status) {
          alert("completed");
        }
});}
$(document).ready(function() {
        var subject = "Hi Subject!";
        var message = "Hi Message!";
        CreateNewItem(subject, message);        
});

Take a look at javascript console in your browser, there you can find useful errors. jQuery and SPServices must be loaded. For your tests you can even use cdn links for jQuery and SPServices.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>
share|improve this answer
    
@Anatoly...thanks for you response. so i changed the references to the ones above that you provided, and checked the console (which is another new thing to me so thanks very much for that!), and I am getting error 'SCRIPT438: Object doesn't support property or method 'SPServices', so I switched it back to what I had in the style library, and I am getting the same error. I assume this is indicating that the reference to SPService is invalid? –  Justin Jun 17 '12 at 14:29
    
also...switched to Announcements list and columns Title and Body for testing. –  Justin Jun 17 '12 at 14:39
1  
The reference to SPServices seems to be invalid. Does the error occur only in IE9? –  Anatoly Mironov Jun 17 '12 at 20:44
2  
Be sure that wherever you are storing the script files that they are available at least for read for everyone. Also make sure the paths are valid in the browser context and not just in SPD. (Try the URL to the .js file in the browser.) –  Marc D Anderson Jun 17 '12 at 21:44
1  
It's got to be a reference issue based on what you've listed so far. Can you add the script file references to your post so that we can see those details as well? –  Marc D Anderson Jun 18 '12 at 1:58
show 6 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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